1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.lib.internal;
12
13 import java.util.concurrent.Executors;
14 import java.util.concurrent.ScheduledThreadPoolExecutor;
15 import java.util.concurrent.ThreadFactory;
16
17
18
19
20 public class WorkQueue {
21 private static final ScheduledThreadPoolExecutor executor;
22
23 static final Object executorKiller;
24
25 static {
26
27
28
29
30
31 int threads = 1;
32 executor = new ScheduledThreadPoolExecutor(threads,
33 new ThreadFactory() {
34 private final ThreadFactory baseFactory = Executors
35 .defaultThreadFactory();
36
37 @Override
38 public Thread newThread(Runnable taskBody) {
39 Thread thr = baseFactory.newThread(taskBody);
40 thr.setName("JGit-WorkQueue");
41 thr.setContextClassLoader(null);
42 thr.setDaemon(true);
43 return thr;
44 }
45 });
46 executor.setRemoveOnCancelPolicy(true);
47 executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
48 executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
49 executor.prestartAllCoreThreads();
50
51
52
53
54
55 executor.setThreadFactory(Executors.defaultThreadFactory());
56
57 executorKiller = new Object() {
58 @Override
59 protected void finalize() {
60 executor.shutdownNow();
61 }
62 };
63 }
64
65
66
67
68
69
70 public static ScheduledThreadPoolExecutor getExecutor() {
71 return executor;
72 }
73 }