@Test public void testPoolPrioritizesFreeThreadsAndExecutes() { threadPool = new ActionThreadPool("Test Action", 2); final List<String> resultList = new CopyOnWriteArrayList<>(); for (int i = 0; i < 20; ++i) { threadPool.execute(new Runnable() { @Override public void run() { resultList.add(Thread.currentThread().getName()); } }); } while (resultList.size() != 20) { } int threadZeroCount = 0; int threadOneCount = 0; for (String threadName : resultList) { if ("Test Action-0".equals(threadName)) { ++threadZeroCount; } if ("Test Action-1".equals(threadName)) { ++threadOneCount; } } assertEquals(10, threadZeroCount); assertEquals(10, threadOneCount); }
@Override public void execute(Runnable action) { ThreadManager nextThread = pool.pollFirst(); boolean submitted = nextThread.submit(action); pool.add(nextThread); if (!submitted) { throw new RejectedExecutionException(); } }
ActionThreadPool implements Executor { @Override public void execute(Runnable action) { ThreadManager nextThread = pool.pollFirst(); boolean submitted = nextThread.submit(action); pool.add(nextThread); if (!submitted) { throw new RejectedExecutionException(); } } }
ActionThreadPool implements Executor { @Override public void execute(Runnable action) { ThreadManager nextThread = pool.pollFirst(); boolean submitted = nextThread.submit(action); pool.add(nextThread); if (!submitted) { throw new RejectedExecutionException(); } } ActionThreadPool(String actionName, int threadCount); }
ActionThreadPool implements Executor { @Override public void execute(Runnable action) { ThreadManager nextThread = pool.pollFirst(); boolean submitted = nextThread.submit(action); pool.add(nextThread); if (!submitted) { throw new RejectedExecutionException(); } } ActionThreadPool(String actionName, int threadCount); @Override void execute(Runnable action); void signalTaskComplete(ThreadManager threadManager); void shutdown(); }
ActionThreadPool implements Executor { @Override public void execute(Runnable action) { ThreadManager nextThread = pool.pollFirst(); boolean submitted = nextThread.submit(action); pool.add(nextThread); if (!submitted) { throw new RejectedExecutionException(); } } ActionThreadPool(String actionName, int threadCount); @Override void execute(Runnable action); void signalTaskComplete(ThreadManager threadManager); void shutdown();  }