Browse Source

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>
master
Matthias Sohn 5 years ago
parent
commit
aea95b819a
  1. 11
      org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java
  2. 4
      org.eclipse.jgit/src/org/eclipse/jgit/nls/GlobalBundleCache.java
  3. 9
      org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java

11
org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java

@ -18,6 +18,8 @@ import java.io.IOException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
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;
/**
@ -170,6 +172,15 @@ public class Git implements AutoCloseable {
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
* interact with the specified git repository.

4
org.eclipse.jgit/src/org/eclipse/jgit/nls/GlobalBundleCache.java

@ -70,4 +70,8 @@ class GlobalBundleCache {
throw new Error(e);
}
}
static void clear() {
cachedBundles.clear();
}
}

9
org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java

@ -100,6 +100,15 @@ public class NLS {
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 ConcurrentHashMap<Class, TranslationBundle> map = new ConcurrentHashMap<>();

Loading…
Cancel
Save