Java Reference
In-Depth Information
}
}
// Generate and send the response
os . println ( "HTTP/1.0 " + errNum + " " + response );
os . println ( "Content-type: text/html" );
os . println ();
os . println ( "<html>" );
os . println ( "<head><title>Error " + errNum + "--" + response +
"</title></head>" );
os . println ( "<h1>" + errNum + " " + response + "</h1>" );
os . println ( "<hr>" );
os . println ( "<address>Java Web Proxy," );
String myAddr = "http://www.darwinsys.com/freeware/" ;
os . println ( "<a href=\"" + myAddr + "\">" +
myAddr + "</a>" );
os . println ( "</address>" );
os . println ( "</html>" );
os . println ();
os . close ();
}
}
From a performance and security point of view, it will be better to precreate a pool of threads
and cause each one to run the Handler when a connection comes along. This is how servlet
engines drive ordinary servlets to high levels of performance; it avoids the overhead of creat-
ing a Thread object for each request. This can be done easily, using the Concurrency Utilit-
ies.
Simplifying Servers Using the Concurrency Utilities
Problem
You need to implement a multithreaded server.
Solution
Use a Thread Pool implementation of the Executor interface.
Search WWH ::




Custom Search