EchoServerThreaded2public class EchoServerThreaded2 extends Object Threaded Echo Server, pre-allocation scheme.
Each Thread waits in its accept() call for a connection; this synchronizes
on the serversocket when calling its accept() method. |
Fields Summary |
---|
public static final int | ECHOPORT | public static final int | NUM_THREADS |
Constructors Summary |
---|
public EchoServerThreaded2(int port, int numThreads)Constructor
ServerSocket servSock;
Socket clientSocket;
try {
servSock = new ServerSocket(ECHOPORT);
} catch(IOException e) {
/* Crash the server if IO fails. Something bad has happened */
throw new RuntimeException("Could not create ServerSocket " + e);
}
// Create a series of threads and start them.
for (int i=0; i<numThreads; i++) {
new Handler(servSock, i).start();
}
|
Methods Summary |
---|
public static void | main(java.lang.String[] av)Main method, to start the servers.
new EchoServerThreaded2(ECHOPORT, NUM_THREADS);
|
|