@@ -0,0 +1,1810 @@
+import java.util.Random;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.ThreadPoolExecutor;%0A%0Aclass TestThread extends Thread %7B%0A%0A%09ThreadCompleteListener listener;%0A%09int index;%0A%0A%09public TestThread(ThreadCompleteListener listener, int index) %7B%0A%09%09this.listener = listener;%0A%09%09this.index = index;%0A%09%7D%0A%0A%09@Override%0A%09public void run() %7B%0A%09%09int count = 0;%0A%09%09Random random = new Random();%0A%09%09while (count %3C 5) %7B%0A%09%09%09System.out.println(%22thread index:%22 + index%0A%09%09%09%09%09+ %22%5Ct executing thread number:%22%0A%09%09%09%09%09+ Work.getInstance().getActiveThreadCount());%0A%09%09%09try %7B%0A%09%09%09%09int i = random.nextInt() %25 3;%0A%09%09%09%09int sleepTime = 500 * i + 500;%0A%09%09%09%09sleep(sleepTime);%0A%09%09%09%09// System.out.println(%22thread index:%22 + index%0A%09%09%09%09// + %22-----------------------%3E%3E%3E sleep time:%22 + sleepTime%0A%09%09%09%09// + %22ms%22);%0A%09%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%09count++;%0A%09%09%7D%0A%09%09System.out.println(%22thread index:%22 + index + %22complete%22);%0A%09%09// listener.onComplete();%0A%09%7D%0A%7D%0A%0Ainterface ThreadCompleteListener %7B%0A%09void onComplete();%0A%7D%0A%0Aclass Work implements ThreadCompleteListener %7B%0A%0A%09static Work instance = new Work();%0A%0A%09int index = 0;%0A%0A%09public static Work getInstance() %7B%0A%09%09return instance;%0A%09%7D%0A%0A%09public int getActiveThreadCount() %7B%0A%09%09return threadPool.getActiveCount();%0A%09%7D%0A%0A%09private ThreadPoolExecutor threadPool;%0A%09private TestThread testThread;%0A%0A%09public void doSomeWork() %7B%0A%09%09testThread = new TestThread(this, index);%0A%09%09threadPool.submit(testThread);%0A%09%09index++;%0A%09%7D%0A%0A%09public void initThreadPool() %7B%0A%09%09threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool();%0A%09%7D%0A%0A%09@Override%0A%09public void onComplete() %7B%0A%09%09doSomeWork();%0A%09%7D%0A%7D%0A%0Apublic class ThreadPoolTest %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09Work work = Work.getInstance();%0A%09%09work.initThreadPool();%0A%09%09for (int i = 0; i %3C 5; i++) %7B%0A%09%09%09work.doSomeWork();%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

add src/ThreadPoolText.java