Browse Source

Use a dedicated executor to run auto-gc in command line interface

WorkQueue uses daemon threads so auto-gc would not be executed after
short-lived commands run in command line. Hence use a dedicated executor
which we shutdown when the command finishes.

Change-Id: I0c2429ecfa04387389d159168ba78a020a696228
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.8
Matthias Sohn 8 years ago
parent
commit
8c59e64412
  1. 19
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java

19
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java

@ -57,6 +57,10 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.awtui.AwtAuthenticator;
import org.eclipse.jgit.awtui.AwtCredentialsProvider;
@ -98,6 +102,8 @@ public class Main {
PrintWriter writer;
private ExecutorService gcExecutor;
/**
*
*/
@ -105,6 +111,17 @@ public class Main {
HttpTransport.setConnectionFactory(new HttpClientConnectionFactory());
CleanFilter.register();
SmudgeFilter.register();
gcExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
private final ThreadFactory baseFactory = Executors
.defaultThreadFactory();
@Override
public Thread newThread(Runnable taskBody) {
Thread thr = baseFactory.newThread(taskBody);
thr.setName("JGit-autoGc"); //$NON-NLS-1$
return thr;
}
});
}
/**
@ -192,6 +209,8 @@ public class Main {
// broken pipe
exit(1, null);
}
gcExecutor.shutdown();
gcExecutor.awaitTermination(10, TimeUnit.MINUTES);
}
PrintWriter createErrorWriter() {

Loading…
Cancel
Save