46
47
// create thread pool
48 tpool = new ThreadPool(5);
49
50
// init, bind, listen
51 serv = new ServerSocket(port);
52
53
System.out.println(“*** listening on port “
54 + port);
55
56
57
while(true)
58 {
59 // accept new connection
60 clnt = serv.accept();
61
62
// add to thread pool
63 tpool.add(clnt);
64 }
65 }
66 catch (NumberFormatException nfe)
67 {
68 // non-numeric port value?
69 System.err.println(“NumberFormatException: “ +
70 nfe.getMessage());
71 }
72 catch(IOException ioe)
73 {
74 // connection failed?
75 System.err.println(“IOException: “
76 + ioe.getMessage());
77 }
78 }
79 }
80
81
class ThreadPool
82 {
83 private Vector m_queue = new Vector();
84
85
public ThreadPool(int thread_count)
86 {
87 WorkerThread wt = null;
88 int x = 0;
89
90
for(x=0; x < thread_count; ++x) ...