Appendix B. Simple Java Web Server

Server.java

 import java.io.*; import java.net.*; import java.util.*; import UrlCache; import MyGetBytes; import LazyDate; import FileInfo; class Server implements HttpConstants { // Print to stdout protected static void p(String s) { System.out.println(s); } // Print to the log file protected static void log(byte[] b) throws IOException { synchronized (log) { log.write(b, 0, b.length); } } static OutputStream log = null; /* our server's configuration information is stored * in these properties */ protected static Properties props = new Properties(); // Where worker threads stand idle static Vector threads = new Vector(); // The web server's virtual root static File root; // Timeout on client connections static ...

Get Java™ Performance and Scalability, Volume 1: Server-Side Programming Techniques now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.