code: public static ThreadPoolExecutor createThreadPoolExecutor(final int queueSize, final String threadName, ThreadFactory threadFactory, final RejectedExecutionHandler policy)
     {
        if (threadFactory == null) {
           threadFactory = new DefaultThreadFactory(threadName, true);
        }
  
        LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(queueSize);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1 /*core*/, 1 /*max*/, 5 /*keepalive*/, SECONDS, queue, threadFactory, policy);
        executor.allowCoreThreadTimeOut(true);
        return executor;
     }
docs: Create a ThreadPoolExecutor.
  
  @param queueSize the queue size
  @param threadName the thread name
  @param threadFactory an optional ThreadFactory
  @param policy the RejectedExecutionHandler policy
  @return a ThreadPoolExecutor