SimpleThreadpool { private SimpleThreadpool(int threadCount) { poolCount.incrementAndGet(); this.runnables = new ConcurrentLinkedQueue<>(); this.execute = new AtomicBoolean(true); this.threads = new ArrayList<>(); for (int threadIndex = 0; threadIndex < threadCount; threadIndex++) { SimpleThreadpoolThread thread = new SimpleThreadpoolThread("SimpleThreadpool" + poolCount.get() + "Thread" + threadIndex, this.execute, this.runnables); thread.start(); this.threads.add(thread); } } private  SimpleThreadpool(int threadCount); static SimpleThreadpool getInstance(); static SimpleThreadpool getInstance(int threadCount); void execute(Runnable runnable); void awaitTermination(long timeout); void awaitTermination(); void terminate(); void stop();  }
@Test public void testSimpleThreadpool() throws Exception { int runnableCount = 10; SimpleThreadpool threadpool = SimpleThreadpool.getInstance(); final AtomicInteger count = new AtomicInteger(0); Runnable r = new Runnable() { @Override public void run() { count.getAndIncrement(); } }; for (int i = 0; i < runnableCount; i++) { threadpool.execute(r); } threadpool.stop(); threadpool.awaitTermination(); Assert.assertEquals("Runnables executed should be same as runnables sent to threadpool", runnableCount, count.get()); }