forked from j62/ctbrec
Add a global ThreadPool
This commit is contained in:
parent
d679bb65ca
commit
3c1e0eea96
|
@ -0,0 +1,32 @@
|
|||
package ctbrec;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class GlobalThreadPool {
|
||||
|
||||
private static ExecutorService threadPool = Executors.newCachedThreadPool(r -> {
|
||||
Thread t = new Thread(r);
|
||||
t.setDaemon(true);
|
||||
t.setName("GlobalWorker-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
return t;
|
||||
});
|
||||
|
||||
private GlobalThreadPool() {
|
||||
}
|
||||
|
||||
public static Future<?> submit(Runnable runnable) { // NOSONAR
|
||||
return threadPool.submit(runnable);
|
||||
}
|
||||
|
||||
public static <T> Future<T> submit(Callable<T> callable) {
|
||||
return threadPool.submit(callable);
|
||||
}
|
||||
|
||||
public static ExecutorService get() {
|
||||
return threadPool;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue