diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF index e4791dc59..0966285ce 100644 --- a/org.eclipse.jgit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/MANIFEST.MF @@ -85,6 +85,7 @@ Export-Package: org.eclipse.jgit.annotations;version="4.8.0", org.eclipse.jgit.treewalk, org.eclipse.jgit.transport, org.eclipse.jgit.submodule", + org.eclipse.jgit.lib.internal;version="4.8.0";x-internal:=true, org.eclipse.jgit.merge;version="4.8.0"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.treewalk, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index 17f3e6ab8..ad611d350 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -78,7 +78,6 @@ import java.util.TreeMap; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -107,6 +106,7 @@ import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref.Storage; +import org.eclipse.jgit.lib.internal.WorkQueue; import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.ReflogReader; @@ -151,7 +151,19 @@ public class GC { private static final int DEFAULT_AUTOLIMIT = 6700; - private static ExecutorService executor = Executors.newFixedThreadPool(1); + private static volatile ExecutorService executor; + + /** + * Set the executor for running auto-gc in the background. If no executor is + * set JGit's own WorkQueue will be used. + * + * @param e + * the executor to be used for running auto-gc + * @since 4.8 + */ + public static void setExecutor(ExecutorService e) { + executor = e; + } private final FileRepository repo; @@ -271,7 +283,7 @@ public class GC { } return Collections.emptyList(); }; - Future> result = executor.submit(gcTask); + Future> result = executor().submit(gcTask); if (background) { // TODO(ms): in 5.0 change signature and return the Future return Collections.emptyList(); @@ -283,6 +295,10 @@ public class GC { } } + private ExecutorService executor() { + return (executor != null) ? executor : WorkQueue.getExecutor(); + } + private Collection doGc() throws IOException, ParseException { if (automatic && !needGc()) { return Collections.emptyList(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java index 54c80522b..a75293d6c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java @@ -46,6 +46,8 @@ package org.eclipse.jgit.lib; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.jgit.lib.internal.WorkQueue; + /** ProgressMonitor that batches update events. */ public abstract class BatchingProgressMonitor implements ProgressMonitor { private long delayStartTime; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java index baa528686..53e9fe3c5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java @@ -55,6 +55,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jgit.annotations.NonNull; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.internal.storage.file.FileRepository; +import org.eclipse.jgit.lib.internal.WorkQueue; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.RawParseUtils; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/WorkQueue.java similarity index 95% rename from org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkQueue.java rename to org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/WorkQueue.java index 07b87f58d..3303f4772 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/WorkQueue.java @@ -41,7 +41,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.eclipse.jgit.lib; +package org.eclipse.jgit.lib.internal; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -50,7 +50,7 @@ import java.util.concurrent.ThreadFactory; /** * Simple work queue to run tasks in the background */ -class WorkQueue { +public class WorkQueue { private static final ScheduledThreadPoolExecutor executor; static final Object executorKiller; @@ -94,7 +94,10 @@ class WorkQueue { }; } - static ScheduledThreadPoolExecutor getExecutor() { + /** + * @return the WorkQueue's executor + */ + public static ScheduledThreadPoolExecutor getExecutor() { return executor; } }