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 ; }
Create a ThreadPoolExecutor .