title: Can I make a Java HttpServer threaded/process requests in parallel?
body: <p>I have built a simple HttpServer following tutorials i have found online, using Sun's lightweight HttpServer.</p>
  
  <p>Basically the main function looks like this:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
          HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
          //Create the context for the server.
          server.createContext("/", new BaseHandler());
  
          server.setExecutor(null); // creates a default executor
          server.start();
      }
  </code></pre>
  
  <p>And I have implemented the BaseHandler Interface's method to process the Http request and return a response.</p>
  
  <pre><code>static class BaseHandler implements HttpHandler {
          //Handler method
          public void handle(HttpExchange t) throws IOException {
  
            //Implementation of http request processing
            //Read the request, get the parameters and print them
            //in the console, then build a response and send it back.
          }
    }
  </code></pre>
  
  <p>I have also created a Client that sends multiple requests via threads. Each thread sends the following request to the server:</p>
  
  <blockquote>
    <p>http://localhost:8000/[context]?int="+threadID</p>
  </blockquote>
  
  <p>On Each client run, The requests seem to arrive in different order to the server, but they are served in a serial manner. </p>
  
  <p>What i wish to acomplish is for the requests to be processed in a parallel manner if that is possible.</p>
  
  <p>Is it possible, for example, to run each handler in a seperate thread, and if so, is it a good thing to do.</p>
  
  <p>Or should i just drop using Sun's lightweight server altogether and focus an building something from scratch?</p>
  
  <p>Thanks for any help.</p>