private static final ThreadPoolExecutor executor = new ThreadPoolExecutor(32, 128, 120, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(512),
r -> {
Thread t = new Thread(r);
t.setUncaughtExceptionHandler((th, e) ->
logger.error(LogBuilder.log("ThreadPoolExecutor", "uncaught exception," + th.getName()), e)
);
t.setName("th" + t.getId());
return t;
},
(r, exec) -> {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RejectedExecutionException("Task " + r.toString() +
" rejected from " +
e.toString());
}
exec.getQueue().add(r);
});