How can I create a thread pool?

John Zukowski

The Executors class of the java.util.concurrent class offers newCachedThreadPool(), newCachedThreadPool(ThreadFactory threadFactory), newFixedThreadPool(int nThreads), newFixedThreadPool(int nThreads, ThreadFactory threadFactory), newScheduledThreadPool(int corePoolSize), and newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory) for creating an ExecutorService to use as a thread pool. Just give the pool a Runnable object to run with its execute() method.