读书人

线程池中全部线程结束捕捉

发布时间: 2012-07-05 07:59:18 作者: rapoo

线程池中所有线程结束捕捉

??下面的代码只是一个引子或者一种方案。????

? ThreadPoolExecutor threadPool=new ThreadPoolExecutor(20, 50, 50000,TimeUnit.MILLISECONDS
??????????? , new ArrayBlockingQueue<Runnable>(5, true));
??????? for(int i=0;i<30;i++)
??????? {
??????????? threadPool.execute(new Runnable()
??????????? {
??????????????? public void run()
??????????????? {
??????????????????? try
??????????????????? {
??????????????????????? int random=getRandom(500, 4000);
??????????????????????? Thread.sleep(random);
??????????????????????? ++count;
??????????????????????? if(count>=30)
??????????????????????? {
????????????????????????? System.out.println("All Thread is Finished!!!!!!!!!!!!!!");?
??????????????????????? }
??????????????????? }catch (InterruptedException e){}
??????????????? }
??????????? });
??????? }

读书人网 >移动开发

热点推荐