小弟最近想用concurrent这个工具包来开发有关多线程方面的项目。请问有那位知道怎样用这个包去创线程池,除了这样的方式还有什么方式:
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); }
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); }
自己顶一下!