This project is a simple multithreaded TCP server implemented in Java using a thread pool. It accepts multiple client connections concurrently and responds with a greeting message. The server is tested with Apache JMeter for load and performance benchmarking.
- Uses ExecutorService with a fixed thread pool.
- Accepts multiple client connections concurrently.
- Responds with a custom message:
Hello from server <client_ip>. - Demonstrates basic multithreaded socket programming in Java.
- Load tested with Apache JMeter.
-
The server starts on port
8010. -
A fixed-size thread pool (default
10threads) is created usingExecutors.newFixedThreadPool(). -
For every incoming client connection:
- A new task is submitted to the thread pool.
- The server sends back a greeting message to the client.
ServerSocket serverSocket = new ServerSocket(port);
Socket clientSocket = serverSocket.accept();
threadPool.execute(() -> handleClient(clientSocket));The handleClient() method sends:
toSocket.println("Hello from server " + clientSocket.getInetAddress());- Java 8 or above
- Apache JMeter (for performance testing)
-
Clone the repository:
git clone https://github.com/NirajSalunke/ThreadPool-Server.git cd ThreadPool-Server -
Compile the server:
javac Server.java
-
Run the server:
java Server
You can test using Netcat or Telnet:
nc localhost 8010Expected output:
Hello from server /127.0.0.1
The server was tested with Apache JMeter 5.6.3 using a TCP Sampler.
- Number of Samples: 13,829
- Average Response Time: ~1 ms
- Median Response Time: 1 ms
- Deviation: 2 ms
- Throughput: ~60,039 requests/minute
- Errors: 0
The graph shows stable throughput with very low latency, demonstrating the efficiency of the thread pool approach.
- Add configurable port and pool size via command-line arguments.
- Implement request/response processing instead of static messages.
- Add logging support.
- Provide a client implementation for easier testing.
- Containerize with Docker for deployment.
This project is licensed under the MIT License - see the LICENSE file for details.