Program 2 (part II) - Multi-Threaded Web Server

Overview

Write a scaled down web server that processes HTTP requests. The server need only handle GET requests. Any header lines following the request line should be read, but ignored. Requests other than GET will also be ignored, but the server can print a message to its standard output (no reply to the client).

In this part II of program 2, the server should be converted to be multi-threaded.

The initial of the program will accept requests from clients but will no longer directly process the requests.

Instead for each client request object ( html page, image on the page, etc.) a new thread should be created to handle only that one request.

From the client's point of view, there will be no apparent difference between this version and the single threaded server.

In your own testing you could, for example, have the multi-threaded server log (to standard output) the thread name for each request with the Thread getName() instance method, but this is not a requirement for what you turn in.

Initial Thread

The initial thread will

Creating the thread

A thread is a concurrent sequential execution of some method in the process's code.

In Java, threads are created as instances of the Thread class and the method a Thread instance executes is constrained to be the run() method in the Runnable interface:


  interface Runnable
  {
     void run();
  }

     When an object implementing interface Runnable is used to create a
     thread, starting the thread causes the object's run method to be
     called in that separately executing thread.

     Notice that run is not declared to throw any exceptions.
     In general, run() should not do the actual work, but should
     call another method. In the other method you are then free to
     declare it with parameters and with whatever throws clause
     is appropriate. The run method can catch any such exceptions.

In Java, since run() takes no arguments, creating the thread to handle a request is done in 2 steps.

Processing Client Requests

The code for processing a single request (that's all each thread should do) will likely not require any changes depending on how you structured part I - the single threaded server.

The loop in part I to handle requests one at a time, should now appear only in the initial thread that listens for client requests.

Each new thread is created to process just one request (and then the thread terminates) will therefore not have a need to loop at all.

Other requirements

All other requirements for part II are the same as for part I.

Turn in Your Server, Part II

Please submit your source code as usual to the Course OnLine site for part II.