# ajaychelikhani/multithreadedwebserverjava architecture

> Architecture diagram of the GitHub repository ajaychelikhani/multithreadedwebserverjava, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ajaychelikhani/multithreadedwebserverjava
- Repository: https://github.com/ajaychelikhani/multithreadedwebserverjava

## Overview

#### 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`](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Server.java) (Server entry point), [`Multithreaded/Server.java`](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Multithreaded/Server.java) (Server entry point), [`ThreadPool/Server.java`](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/ThreadPool/Server.java) (Server entry point), [`Singlethreaded/Client.java`](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Client.java) (Client launcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_single["Single-threaded"]
  node_single_client["Client launcher<br/>Java client<br/>[Client.java]"]
  node_single_server["Server entry point<br/>Java server<br/>[Server.java]"]
  node_single_session["Inline session handling<br/>execution path<br/>[Server.java]"]
end

subgraph group_multi["Thread-per-connection"]
  node_multi_client["Client launcher<br/>Java client<br/>[Client.java]"]
  node_multi_server["Server entry point<br/>Java server<br/>[Server.java]"]
  node_client_thread["Per-client thread<br/>concurrency worker<br/>[Server.java]"]
end

subgraph group_pool["Thread pool"]
  node_pool_server["Server entry point<br/>Java server<br/>[Server.java]"]
  node_worker_pool["Reusable worker pool<br/>bounded execution<br/>[Server.java]"]
  node_pooled_session["Client session<br/>worker task<br/>[Server.java]"]
end

node_tcp{{"TCP sockets<br/>external boundary"}}
node_java["Java runtime"]

node_single_client -->|"connects"| node_tcp
node_tcp -->|"accepts socket"| node_single_server
node_single_server -->|"handles inline"| node_single_session
node_multi_client -->|"connects"| node_tcp
node_tcp -->|"accepts socket"| node_multi_server
node_multi_server -->|"creates thread"| node_client_thread
node_tcp -->|"accepts socket"| node_pool_server
node_pool_server -->|"submits socket work"| node_worker_pool
node_worker_pool -->|"executes"| node_pooled_session
node_java -.->|"runs"| node_single_server
node_java -.->|"runs"| node_multi_server
node_java -.->|"runs"| node_pool_server

click node_single_client "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Client.java"
click node_single_server "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Server.java"
click node_single_session "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Server.java"
click node_multi_client "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Multithreaded/Client.java"
click node_multi_server "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Multithreaded/Server.java"
click node_client_thread "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Multithreaded/Server.java"
click node_pool_server "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/ThreadPool/Server.java"
click node_worker_pool "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/ThreadPool/Server.java"
click node_pooled_session "https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/ThreadPool/Server.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_single_client,node_single_server,node_single_session toneBlue
class node_multi_client,node_multi_server,node_client_thread toneAmber
class node_pool_server,node_worker_pool,node_pooled_session toneMint
class node_tcp,node_java toneNeutral
```

## Components

### Single-threaded

Sequential baseline implementation.

- [Client launcher](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Client.java): Java client · `Singlethreaded/Client.java`
- [Server entry point](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Server.java): Java server · Accepts and handles one client at a time. · `Singlethreaded/Server.java`
- [Inline session handling](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Singlethreaded/Server.java): execution path · A slow client blocks later accepts. · `Singlethreaded/Server.java`

### Thread-per-connection

Creates one thread for each accepted client.

- [Client launcher](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Multithreaded/Client.java): Java client · `Multithreaded/Client.java`
- [Server entry point](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Multithreaded/Server.java): Java server · Accept loop admits client sockets. · `Multithreaded/Server.java`
- [Per-client thread](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/Multithreaded/Server.java): concurrency worker · Runs each client session independently. · `Multithreaded/Server.java`

### Thread pool

Delegates accepted sockets to reusable workers.

- [Server entry point](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/ThreadPool/Server.java): Java server · Accepts sockets and delegates their work. · `ThreadPool/Server.java`
- [Reusable worker pool](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/ThreadPool/Server.java): bounded execution · Controls concurrent session capacity. · `ThreadPool/Server.java`
- [Client session](https://github.com/ajaychelikhani/multithreadedwebserverjava/blob/master/ThreadPool/Server.java): worker task · Processes a connected socket and closes resources. · `ThreadPool/Server.java`

### Other components

- **TCP sockets**: external boundary · Local or remote socket communication.
- **Java runtime**: runtime · Java networking and concurrency APIs.

## Connections

- 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
