A Java-based web server implementation demonstrating different threading approaches for handling concurrent client connections.
MultithreadedWebServer/
├── SingleThreaded/
│ ├── Client.java
│ └── Server.java
├── Multithreaded/
│ ├── Client.java
│ └── Server.java
└── ThreadPool/
└── Server.java
- Location:
SingleThreaded/ - Port: 8010
- Description: Basic server that handles one client at a time sequentially
- Limitation: Cannot handle concurrent connections
- Location:
Multithreaded/ - Port: 8010
- Description: Creates a new thread for each client connection
- Features:
- Handles multiple concurrent clients
- Client spawns 100 concurrent connections for testing
- Uses try-with-resources for proper resource management
- Location:
ThreadPool/ - Port: 8010
- Description: Uses a fixed thread pool to manage client connections efficiently
- Features:
- Fixed pool size of 10 threads
- Better resource management than creating unlimited threads
- Reuses threads for multiple client connections
-
Single-Threaded Server:
cd SingleThreaded javac Server.java java Server -
Multithreaded Server:
cd Multithreaded javac Server.java java Server -
Thread Pool Server:
cd ThreadPool javac Server.java java Server
-
Single-Threaded Client:
cd SingleThreaded javac Client.java java Client -
Multithreaded Client (creates 100 concurrent connections):
cd Multithreaded javac Client.java java Client
- Socket Communication: TCP socket-based client-server communication
- Concurrent Handling: Different approaches to handle multiple clients
- Resource Management: Proper closing of sockets and streams
- Error Handling: Exception handling for network operations
| Implementation | Concurrency | Resource Usage | Scalability |
|---|---|---|---|
| Single-Threaded | None | Low | Poor |
| Multithreaded | Unlimited threads | High | Limited by system |
| Thread Pool | Fixed pool | Controlled | Good |
- Java 8 or higher
- Network connectivity (localhost)
- All servers listen on port 8010
- Single-threaded client connects to port 8090 (different from servers)
- Servers have socket timeout configured (20-70 seconds)
- Multithreaded client demonstrates load testing with 100 concurrent connections