[Oogway] Create a simple multithreaded Http echo server
Write a minimal multi-threaded HTTP echo server that accepts connections in a main thread, hands connections to an available worker thread from a thread pool, parses and processes the POST request in the worker thread, ignores path specified in the POST, and sends a 200 OK response with the same content-type header and payload from the request. In other words, echo back the content to the client.
Download NetBeans from : https://netbeans.org/downloads/
- Import the entire project in your NetBeans IDE and build and run it.
- Clone the Client Program for testing the working of the HttpEchoServer. https://github.com/Talina06/HttpTestClient.git
Test Scenario 1: Testing multi-threaded execution and blocking of accept call when all threads are busy.
- Configuration: src/httpechoserver/Config.java
- maxThreadCount = 1 //i.e maximum one thread processes a single request at a time in the ThreadPool.
- backlogCount = 2 //i.e 2 requests are waiting while the ThreadPool is full.
- Start around 10 instances of the HttpTestClient program.
- The server will process one request at a time, and put 2 requests in the pendingQueue.
- Each time a thread is available, the server pops a request from the pendingQueue and pushes the next incoming request onto the pendingQueue.
- While the above is happening, the next incoming requests are not accepted by the server, until queue has space available.
Test Scenarios 2: Testing Clean Server Termination.
- Same configuration as Test 1.
- shutDownTime = 10 Seconds. // i.e: time limit for all threads to shutdown gracefully.
- Add a System.exit() call after processing one request in the WorkerThread class.
- Start around 3-4 instances of the HttpTestClient program.
- When the server processes the first request, it exits due to the System.exit() call.
- This invoked the shutdownhook and the server proceeds to close all active/waiting threads in the ThreadPool.
- Then, the Server Socket is closed.