Databases Reference
In-Depth Information
}
catch (java.lang.ClassNotFoundException e1) {
System.err.println(e1.toString());
}
catch (java.sql.SQLException e2){
System.err.println(e2.toString());
}
}
catch (java.io.IOException e3){
System.err.println("Unable to bind to port 8888.");
System.err.println(e3.toString());
System.err.println("Hit any key to continue.");
try {
System.in.read();
}
catch (java.io.IOException e4){
System.out.println(e4.toString());
}
}
}//end FortuneServer() constructor
/**
* Uses the socket.accept() method to wait for an incoming request. The
* server indicates how many requests it has processed, determines if
* it needs to dump statistical information to the log file (currently
* done after every 50 requests), and then starts a new
* RequestProcessor thread to handle the request. The RequestProcessor
* object is passed the client's socket information as well as a JDBC
* statement object that is used to query the MSAccess database.
* This method is run in a while(true) loop and can only be terminated
* by system shutdown or CTRL-C.
* @param none
* @see RequestProcessor
* @exception IOException thrown if unable to accept incoming client
* requests
* @return none
*/
private void runServer(){
while (true){
try {
clientSocket = fortuneSocket.accept();
System.out.println("Processing request number " +
(++numberOfRequests));
if (numberOfRequests % DATA_DUMP == 0)
writeStatistics();
(new RequestProcessor(clientSocket, stmt)).start();
}
catch (java.io.IOException e){
System.out.println("Unable to fulfill fortune request.");
System.out.println(e.toString());
}
}
}//end runServer()
/**
* Creates a new FortuneServer object and calls the thread's start
* method. @param args[] a series of command line arguments stored in
* array; not used.
* @exception none
Exhibit 34-8. (
continued
)
Search WWH ::




Custom Search