A Java-based HTTP web server showcasing three server models: Single-threaded, multi-threaded, and thread-pool based implementations. This project demonstrates practical understanding of Java concurrency, networking, and performance trade-offs.
- Single-threaded server implementation
- Multi-threaded server (thread-per-request model)
- Thread pool–based server using
ExecutorService - Handles multiple client connections
- Basic HTTP request parsing
- Supports GET requests
- Clean separation of server and request-handling logic
- Lightweight and dependency-free
- Java 17 (Java 8+ compatible)
- Java Sockets (
ServerSocket,Socket) - Java Threads
ExecutorService& Thread Pools- Java I/O Streams
- Processes one client request at a time
- Simple and easy to understand
- Blocks all incoming requests while processing
Use case: Learning basics of sockets & request handling
- Creates a new thread for each client connection
- Supports concurrent request handling
- Can lead to high resource usage under heavy load
Use case: Moderate traffic, learning concurrency
- Uses a fixed-size thread pool via
ExecutorService - Reuses worker threads efficiently
- Prevents uncontrolled thread creation
- Best balance between performance and resource usage
Use case: Production-like server model
src/
├── main/
│ ├── java/
│ │ ├── src/
│ │ │ ├── SingleThreadedServer
│ │ │ ├── MultiThreadedServer
│ │ │ ├── ThreadPoolServer
-
Server starts and listens on a port
-
Client sends HTTP request
-
Connection is accepted
-
Request is handled based on server model:
- Single thread
- New thread per request
- Thread pool worker
-
HTTP response is returned
-
Connection is closed
java SingleThreadedServerjava MultiThreadedServerjava ThreadPoolServerServer runs at:
http://localhost:8080
- Open multiple browser tabs
- Use
curlor Apache Bench - Observe performance differences between models
- Compare response times and throughput
- Configurable thread pool size
- Request queue monitoring
- Support for POST requests
- Static file serving
- Graceful shutdown
- Performance benchmarking