ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ExecutorService.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ExecutorService.java (file contents):
Revision 1.22 by dl, Sat Dec 27 19:26:25 2003 UTC vs.
Revision 1.23 by dl, Fri Jan 2 00:38:33 2004 UTC

# Line 34 | Line 34 | import java.security.PrivilegedException
34   * <p>The {@link Executors} class provides factory methods for the
35   * executor services provided in this package.
36   *
37 + * <h3>Usage Example</h3>
38 + *
39 + * Here is a sketch of a network service in which threads in a thread
40 + * pool service incoming requests. It uses the preconfigured {@link
41 + * Executors#newFixedThreadPool} factory method:
42 + *
43 + * <pre>
44 + * class NetworkService {
45 + *    private final ServerSocket serverSocket;
46 + *    private final ExecutorService pool;
47 + *
48 + *    public NetworkService(int port, int poolSize) throws IOException {
49 + *      serverSocket = new ServerSocket(port);
50 + *      pool = Executors.newFixedThreadPool(poolSize);
51 + *    }
52 + *
53 + *    public void serve() {
54 + *      try {
55 + *        for (;;) {
56 + *          pool.execute(new Handler(serverSocket.accept()));
57 + *        }
58 + *      } catch (IOException ex) {
59 + *        pool.shutdown();
60 + *      }
61 + *    }
62 + *  }
63 + *
64 + *  class Handler implements Runnable {
65 + *    private final Socket socket;
66 + *    Handler(Socket socket) { this.socket = socket; }
67 + *    public void run() {
68 + *      // read and service request
69 + *    }
70 + * }
71 + * </pre>
72   * @since 1.5
73   * @author Doug Lea
74   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines