EagerThreadPoolExecutor extends ThreadPoolExecutor { @Override public void execute(Runnable command) { if (command == null) { throw new NullPointerException(); } submittedTaskCount.incrementAndGet(); try { super.execute(command); } catch (RejectedExecutionException rx) { final TaskQueue queue = (TaskQueue) super.getQueue(); try { if (!queue.retryOffer(command, 0, TimeUnit.MILLISECONDS)) { submittedTaskCount.decrementAndGet(); throw new RejectedExecutionException("Queue capacity is full."); } } catch (InterruptedException x) { submittedTaskCount.decrementAndGet(); throw new RejectedExecutionException(x); } } catch (Throwable t) { submittedTaskCount.decrementAndGet(); } } EagerThreadPoolExecutor(int corePoolSize,
                                   int maximumPoolSize,
                                   long keepAliveTime,
                                   TimeUnit unit, TaskQueue<Runnable> workQueue,
                                   ThreadFactory threadFactory,
                                   RejectedExecutionHandler handler); int getSubmittedTaskCount(); @Override void execute(Runnable command);  }
@Test public void testEagerThreadPool() throws Exception { String name = "eager-tf"; int queues = 5; int cores = 5; int threads = 10; long alive = 1000; TaskQueue<Runnable> taskQueue = new TaskQueue<Runnable>(queues); final EagerThreadPoolExecutor executor = new EagerThreadPoolExecutor(cores, threads, alive, TimeUnit.MILLISECONDS, taskQueue, new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, URL)); taskQueue.setExecutor(executor); for (int i = 0; i < 15; i++) { Thread.sleep(50); executor.execute(new Runnable() { @Override public void run() { System.out.println("thread number in current pool：" + executor.getPoolSize() + ", task number in task queue：" + executor.getQueue() .size() + " executor size: " + executor.getPoolSize()); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }); } Thread.sleep(5000); Assert.assertTrue("more than cores threads alive!", executor.getPoolSize() == cores); }