This repository contains implementations of a simple HTTP server in Java with three different concurrency models: SingleThreaded, MultiThreaded, and ThreadPool.
MultiThreaded
Server.java
Client.java
SingleThreaded
Server.java
Client.java
ThreadPool
Server.java
This project demonstrates three different approaches to handling multiple client requests concurrently in a server:
-
SingleThreaded:
In the single-threaded model, the server processes one client request at a time. This is simple to implement but can only handle one request concurrently, making it less suitable for real-time or high-traffic applications. -
MultiThreaded:
In the multi-threaded model, the server creates a new thread for each client request. This allows multiple clients to be served simultaneously, providing better concurrency than the single-threaded model. However, creating a new thread for each request can become inefficient and resource-intensive under heavy load. -
ThreadPool:
In the thread pool model, the server maintains a fixed number of reusable threads in a pool. When a client request is received, it is assigned to an available thread from the pool. This approach is more efficient than spawning new threads for each request, especially for applications with fluctuating or high request volumes, as it controls the number of active threads.
Ensure you have Java Development Kit (JDK) version 17 installed. If not, install it using the following commands:
sudo apt-get update
sudo apt-get install openjdk-17-jdk
To clone this repository, open your terminal and run:
git clone https://github.com/Jainish-Prajapati/Http-Server.git
cd Http-Server
Each concurrency model has its own directory with server and client files. Follow these steps to compile and run the code for each model.
Eg. of Multithreaded
/*navigate to directory*/
cd MultiThreaded
/*Compile files*/
javac Server.java
javac Client.java
and similarly you can compile and run single threaded and threadpool servers too.
It's just an implementation of simple http server, developed to understand exactly how servers works internally irl !!