Skip to content

Java web server demonstrating three threading approaches: single-threaded, multithreaded, and thread pool. Features TCP socket communication, concurrent client handling, and load testing with 100+ connections. Compares performance and scalability of different concurrency models.

Notifications You must be signed in to change notification settings

deepanshoo/Multithreaded-Web-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multithreaded Web Server

A Java-based web server implementation demonstrating different threading approaches for handling concurrent client connections.

Project Structure

MultithreadedWebServer/
├── SingleThreaded/
│   ├── Client.java
│   └── Server.java
├── Multithreaded/
│   ├── Client.java
│   └── Server.java
└── ThreadPool/
    └── Server.java

Implementations

1. Single-Threaded Server

  • Location: SingleThreaded/
  • Port: 8010
  • Description: Basic server that handles one client at a time sequentially
  • Limitation: Cannot handle concurrent connections

2. Multithreaded Server

  • 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

3. Thread Pool Server

  • 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

How to Run

Running the Servers

  1. Single-Threaded Server:

    cd SingleThreaded
    javac Server.java
    java Server
  2. Multithreaded Server:

    cd Multithreaded
    javac Server.java
    java Server
  3. Thread Pool Server:

    cd ThreadPool
    javac Server.java
    java Server

Running the Clients

  1. Single-Threaded Client:

    cd SingleThreaded
    javac Client.java
    java Client
  2. Multithreaded Client (creates 100 concurrent connections):

    cd Multithreaded
    javac Client.java
    java Client

Key Features

  • 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

Performance Comparison

Implementation Concurrency Resource Usage Scalability
Single-Threaded None Low Poor
Multithreaded Unlimited threads High Limited by system
Thread Pool Fixed pool Controlled Good

Requirements

  • Java 8 or higher
  • Network connectivity (localhost)

Notes

  • 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

About

Java web server demonstrating three threading approaches: single-threaded, multithreaded, and thread pool. Features TCP socket communication, concurrent client handling, and load testing with 100+ connections. Compares performance and scalability of different concurrency models.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages