请问谁用过util.concurrent包? 这个包是美国的一个大学教授(Doug Lea )写的,目前还在jcp被审,估计会加到jdk1.5中http://www.jcp.org/en/jsr/detail?id=166用过一些这个包里关于线程池的部分,感觉不错。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to chenyuan_tongji(codeguru)方便的话,可以把你写的线程池的部分给我看看好吗?谢谢。[email protected] class WebService { public static void main(String[] args) { PooledExecutor pool = new PooledExecutor(new BoundedBuffer(10), 20); pool.createThreads(4); try { ServerSocket socket = new ServerSocket(9999); for (;;) { final Socket connection = socket.accept(); pool.execute(new Runnable() { public void run() { new Handler().process(connection); } }); } }catch(Exception e) { } // die }}class Handler { void process(Socket s); } 我没有编写任何线程池,这个包提供了线程池,我做的只是把自己的线程放进去。参考Doug Lea的页面:http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html 我已经贴出来了,就是上面那段代码,使用了concurrent包里面的PooledExecutor类。 看一下 远程登录计算机 关于用java 6 登陆校内网 ArcEngine开发遇到的问题 TOMCAT下JSP文件文件放置的疑问? 如何写大的XML文件,文件大小在300M以上。在PC机上。 判断传入的字符串对象是整型的最标准方法是什么? 怎么把线程搞的久一点,比LONG值还要大?? struts错误和信息显示标签 又是一个很菜的问题但是不得不麻烦大哥大姐了啊~ 有趣的小问题(多线程) 随机数的算法求解
方便的话,可以把你写的线程池的部分给我看看好吗?谢谢。
[email protected]
public static void main(String[] args) {
PooledExecutor pool = new PooledExecutor(new BoundedBuffer(10), 20);
pool.createThreads(4);
try {
ServerSocket socket = new ServerSocket(9999);
for (;;) {
final Socket connection = socket.accept();
pool.execute(new Runnable() {
public void run() {
new Handler().process(connection);
}
});
}
}catch(Exception e) { } // die
}
}class Handler { void process(Socket s); }
http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html