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