
| package org.javaresearch.j2seimproved.thread; import java.net.*; import EDU.oswego.cs.dl.util.concurrent.*; public class TestExecutor { 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 } static class Handler { void process(Socket s){ } } } |
关注此文的读者还看过: