forked from j62/ctbrec
1
0
Fork 0

Add a global ThreadPool

This commit is contained in:
0xb00bface 2021-01-10 20:13:15 +01:00
parent d679bb65ca
commit 3c1e0eea96
1 changed files with 32 additions and 0 deletions

View File

@ -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;
}
}