Here we will modify the server so that it can serve


(A) Test Environment

Here, we will modify the server so that it can serve multiple connections simultaneously. First, let's create a testing environment.

Download StressTest.java and add it to your project. It creates many simultaneous connections (using threads) to the server. It is meant to be run after starting the web server.

The method getURLQ returns the URL to be retrieved. You can change it to retrieve either the main page or the /address form, whereas the address form is actually a submission to add another address to the database. You can change it to suit your needs (e.g., if you don't use port 12345).

Start your server, then start StressTest.java (right-click on the file, select Run to run it). The output should be like so:

finished. 3080 ms.

500 out of 500 successful.

The program expects the server to always send back the same page - otherwise it won't count as "successful".

Note the execution time.

(B) Change the server

Now for the programming bit.

Change the server so that for each incoming connection, you create a new thread. You will need to make an object of a new class HttpConnection for each connection. The run method of this class will handle the connection, receive the incoming requests such as GET / HTTP/1.1 and make the View object to produce a view.

After the connection object is created, make a new Thread object with it, and start the thread with the Thread.start() method. Read up in your favorite textbook (and/or the slides or the example code from last time) on how to do this in detail.

Think about which shared resources the thread will have. You will find that you'll naturally keep resources in the connection object. That's why these objects (implementing Runnable) are so useful -it's easy to see which resources will be shared between threads.

Are the data structures thread-safe? If not, when do you need to protect them? Add appropriate code to use thread-safe data structures or "synchronize" the essential code blocks.

Hint: if you don't want to add "serialized" blocks, consider using a data structure that is better than AddressList for this purpose, and that supports concurrency:

Queue addresses = new ConcurrentLinkedQueue();

Attachment:- Assignment Files.rar

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Here we will modify the server so that it can serve
Reference No:- TGS02657331

Expected delivery within 24 Hours