How ajaychelikhani/multithreadedwebserverjava works
Purpose and Entry Points
This repository demonstrates three Java socket-server concurrency models: single-threaded handling, thread-per-client handling, and thread-pool handling. Each model exposes a Server entry point; client launchers are present for the first two variants.
• Singlethreaded/Server.java
• Multithreaded/Server.java
• ThreadPool/Server.java
Single-Threaded Server Model
Singlethreaded/Server.java is the sequential baseline. It accepts a client connection and processes it before returning to accept another connection. Connection handling and request processing share one execution path, so a slow client blocks later clients.
• Singlethreaded/Server.java
• Singlethreaded/Client.java
Thread-Per-Connection Model
Multithreaded/Server.java separates accepting sockets from handling them by creating independent threads for accepted clients. The accept loop remains responsible for admitting connections, while each client session runs concurrently in its own thread.
• Multithreaded/Server.java
• Multithreaded/Client.java
Thread-Pool Server Model
ThreadPool/Server.java uses a bounded/reusable worker model rather than creating a new thread for every client. Accepted client work is delegated to pooled workers, creating a control boundary between socket admission and execution capacity.
• ThreadPool/Server.java
Primary Flow
Across variants, the core flow is:
1. A server process opens a listening socket.
2. A client process connects and exchanges data with the server.
3. The server handles the connected socket according to its concurrency strategy.
4. The session completes and associated socket resources are closed.
Client-side initiation is represented in:
• Singlethreaded/Client.java
• Multithreaded/Client.java
Runtime and External Boundary
The code targets the Java runtime and Java networking APIs. The material external boundary is TCP socket communication between local or remote client and server processes; there are no repository-visible databases, web frameworks, message brokers, or deployment infrastructure.
Architectural Comparison
The directories are intentionally parallel implementations of the same server responsibility:
• Singlethreaded/Server.java: lowest complexity, serialized throughput.
• Multithreaded/Server.java: concurrent sessions with unbounded thread-creation risk.
• ThreadPool/Server.java: concurrency with worker reuse and controlled execution resources.
Main entry points: Singlethreaded/Server.java Server entry point · Multithreaded/Server.java Server entry point · ThreadPool/Server.java Server entry point · Client.java Client launcher
Components 11
Single-threaded
Sequential baseline implementation.
- Client launcher
Singlethreaded/Client.java - Server entry point · Accepts and handles one client at a time.
Singlethreaded/Server.java - Inline session handling · A slow client blocks later accepts.
Singlethreaded/Server.java
Thread-per-connection
Creates one thread for each accepted client.
- Client launcher
Multithreaded/Client.java - Server entry point · Accept loop admits client sockets.
Multithreaded/Server.java - Per-client thread · Runs each client session independently.
Multithreaded/Server.java
Thread pool
Delegates accepted sockets to reusable workers.
- Server entry point · Accepts sockets and delegates their work.
ThreadPool/Server.java - Reusable worker pool · Controls concurrent session capacity.
ThreadPool/Server.java - Client session · Processes a connected socket and closes resources.
ThreadPool/Server.java
Other components
- TCP sockets · Local or remote socket communication.
- Java runtime · Java networking and concurrency APIs.
Connections 12
- Client launcher → TCP sockets: connects
- TCP sockets → Server entry point: accepts socket
- Server entry point → Inline session handling: handles inline
- Client launcher → TCP sockets: connects
- TCP sockets → Server entry point: accepts socket
- Server entry point → Per-client thread: creates thread
- TCP sockets → Server entry point: accepts socket
- Server entry point → Reusable worker pool: submits socket work
- Reusable worker pool → Client session: executes
- Java runtime → Server entry point: runs
- Java runtime → Server entry point: runs
- Java runtime → Server entry point: runs