快速业务通道

Java中使用Executors创建和管理线程 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-18
ExecutorService minPriorityExec = Executors         .newCachedThreadPool(new MinPriorityThreadFactory());     for (int i = 0; i < 10; i++)       daemonExec.execute(new MyThread(i));     for (int i = 10; i < 20; i++)       if (i == 10)         maxPriorityExec.execute(new MyThread (i));       else if (i == 11)         minPriorityExec.execute(new MyThread (i));       else         defaultExec.execute(new MyThread(i));    } }

结果:

Create Thread-0 Create Thread-1 Create Thread-2 Create Thread-3 Thread-0 run 1 time(s) Thread-0 run 2 time(s) Thread-1 run 1 time(s) Thread-1 run 2 time(s) Thread-2 run 1 time(s) Thread-2 run 2 time(s) Create Thread-4 Thread-4 run 1 time(s) Thread-4 run 2 time(s) Create Thread-5 Thread-5 run 1 time(s) Thread-5 run 2 time(s) Create Thread-6 Create Thread-7 Thread-7 run 1 time(s) Thread-7 run 2 time(s) Create Thread-8 Thread-8 run 1 time(s) Thread-8 run 2 time(s) Create Thread-9 Create Thread-10 Thread-10 run 1 time(s) Thread-10 run 2 time(s) Create Thread-11 Thread-9 run 1 time(s) Thread-9 run 2 time(s) Thread-6 run 1 time(s) Thread-6 run 2 time(s) Thread-3 run 1 time(s) Thread-3 run 2 time(s) Create Thread-12 Create Thread-13 Create Thread-14 Thread-12 run 1 time(s) Thread-12 run 2 time(s) Thread-13 run 1 time(s) Thread-13 run 2 time(s) Create Thread-15 Thread-15 run 1 time(s) Thread-15 run 2 time(s) Create Thread-16 Thread-16 run 1 time(s) Thread-16 run 2 time(s) Create Thread-17 Create Thread-18 Create Thread-19 Thread-14 run 1 time(s) Thread-14 run 2 time(s) Thread-17 run 1 time(s) Thread-17 run 2 time(s) Thread-18 run 1 time(s) Thread-18 run 2 time(s) Thread-19 run 1 time(s) Thread-19 run 2 time(s) Thread-11 run 1 time(s) Thread-11 run 2 time(s)

本文出自 “子 孑” 博客,请务必保留此出处 http://zhangjunhd.blog.51cto.com/113473/70068

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号