I want to use the same thread pool throughout my application. To this end, I can make ExecutorService
static and global so that I can invoke ThreadUtil.executorService
to get ExecutorService
when I need it.
public class ThreadUtil {
public static final ExecutorService executorService = Executors.newCachedThreadPool();
}
Is it OK to instance multiple thread pools like this?
In addition, my application is a TCP server. If I don't know how big the pool should be, is it ok to simply use newCachedThreadPool
?