读书人

ThreadPoolExecutor入门拾掇

发布时间: 2013-08-23 15:57:36 作者: rapoo

ThreadPoolExecutor入门整理
ThreadPoolExecutor boss = new ThreadPoolExecutor(1, 20, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(100000)); // test1 // ThreadPoolExecutor boss = new ThreadPoolExecutor(1, 20, 0L, TimeUnit.MILLISECONDS, new // ArrayBlockingQueue(100)); // test2 for (int i = 0; i < 10000; ++i) { System.out.println(i); try { boss.submit(new Runnable() { @Override public void run() { while (true) { try { Thread.currentThread().sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }); } catch (Exception e) { System.out.println("error: " + i); } } System.out.println("================"); System.out.println(boss.getActiveCount() + "," + boss.getTaskCount()); System.out.println(boss.getPoolSize() + "," + boss.getCorePoolSize() + "," + boss.getMaximumPoolSize()); System.out.println(boss.getQueue().size()); System.in.read();

?

================
1,10000
1,1,20
9999

读书人网 >其他相关

热点推荐