瀏覽代碼

Add Git#shutdown for releasing resources held by JGit process

The shutdown method releases
- ThreadLocal held by NLS
- GlobalBundleCache used by NLS
- Executor held by WorkQueue

Bug: 437855
Bug: 550529
Change-Id: Icfdccd63668ca90c730ee47a52a17dbd58695ada
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v5.8.0.202006091008-r
Matthias Sohn 4 年之前
父節點
當前提交
aea95b819a

+ 11
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java 查看文件

import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder; import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.lib.RepositoryCache; import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.lib.internal.WorkQueue;
import org.eclipse.jgit.nls.NLS;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;


/** /**
return new InitCommand(); return new InitCommand();
} }


/**
* Shutdown JGit and release resources it holds like NLS and thread pools
* @since 5.8
*/
public static void shutdown() {
WorkQueue.getExecutor().shutdownNow();
NLS.clear();
}

/** /**
* Construct a new {@link org.eclipse.jgit.api.Git} object which can * Construct a new {@link org.eclipse.jgit.api.Git} object which can
* interact with the specified git repository. * interact with the specified git repository.

+ 4
- 0
org.eclipse.jgit/src/org/eclipse/jgit/nls/GlobalBundleCache.java 查看文件

throw new Error(e); throw new Error(e);
} }
} }

static void clear() {
cachedBundles.clear();
}
} }

+ 9
- 0
org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java 查看文件

return b.get(type); return b.get(type);
} }


/**
* Release resources held by NLS
* @since 5.8
*/
public static void clear() {
local.remove();
GlobalBundleCache.clear();
}

private final Locale locale; private final Locale locale;
private final ConcurrentHashMap<Class, TranslationBundle> map = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Class, TranslationBundle> map = new ConcurrentHashMap<>();



Loading…
取消
儲存