How To Naming ThreadPoolExecutor

How To Naming ThreadPoolExecutor

How To Naming ThreadPoolExecutor

How To Naming ThreadPoolExecutor

Example:
private static final ThreadPoolExecutor service = new ThreadPoolExecutor(500, 30000, 60L,
TimeUnit.SECONDS, new SynchronousQueue<>(), new NamedThreadFactory(“SpecificName”),
(runnable, executor) -> {
if (!executor.isShutdown()) {
LogUtils.system.error(“All threads in the pool are currently busy”);
runnable.run();
}
});

public record NamedThreadFactory(String prefix) implements ThreadFactory {
@Override
public Thread newThread(@NotNull Runnable r) {
return new Thread(r, prefix + “-“ + System.currentTimeMillis());
}
}

這樣輸出log會變成prefix + 時間戳記