This project is a Java-based multi-threaded, distributed application that demonstrates client-server communication, concurrent task delegation, and load balancing.
The system consists of three main components:
- Master node
- Multiple Client nodes
- Multiple Slave (Worker) nodes
Clients submit jobs (Type A or Type B) to the Master, which intelligently schedules and distributes them to connected Slaves based on current queue loads and optimal processing times.
Once a Slave completes a job, the Master is notified and sends the confirmation back to the original Client.
The central coordinator of the system.
It runs two ServerSocket listeners simultaneously:
- Client Port (12486) – Listens for incoming client connections and job requests.
- Slave Port (12487) – Listens for connecting worker nodes.
The Master uses extensive multi-threading:
- Listener threads
- Reader threads
- Writer threads
These exist for both clients and slaves, allowing the system to remain:
- Event-driven
- Non-blocking
Incoming jobs are passed to a Load Balancer, which calculates the projected completion time for each slave queue.
Processing times:
- Optimal jobs: 2 seconds
- Non-optimal jobs: 10 seconds
The Master routes each job to the Slave with the lowest projected completion time.
Worker nodes process jobs assigned by the Master.
Slave A
- Optimized for Type A jobs
- Completes in 2 seconds
- Processes Type B jobs sub-optimally (10 seconds)
Slave B
- Optimized for Type B jobs
- Completes in 2 seconds
- Processes Type A jobs sub-optimally (10 seconds)
End-user nodes that connect to the Master.
Clients:
- Provide an interactive terminal interface
- Submit jobs (Type A or Type B)
- Asynchronously listen for
JOB_COMPLETEmessages from the Master.
- Java Development Kit (JDK) — Version 8 or higher
- A terminal / command-line interface
Navigate to the src directory containing the os_term_project package and compile all .java files:
javac os_term_project/*.javaThe Master must be started first so that clients and slaves have a server to connect to.
java os_term_project.MasterNote:
The master will output logs indicating it is listening on:
- Port 12486 (Clients)
- Port 12487 (Slaves)
Open new terminal windows for each Slave.
You must specify:
- Slave Type (
AorB) - Hostname
- Port (
12487)
java os_term_project.Slave A localhost 12487java os_term_project.Slave B localhost 12487Open a new terminal window to act as a Client.
You must specify:
- Client identifier
- Hostname
- Port (
12486)
java os_term_project.Client A localhost 12486You can run multiple clients concurrently in separate terminals.
In the Client terminal, you will see:
Please enter a message to send to the Master:
What job would you like to do? Job A or Job B.
Type A or B to send a job to the Master.
Or type -1 to exit.
- Type A → Submit Job A
- Type B → Submit Job B
- Type -1 → Disconnect the client
- The Client sends a job request.
- The Master calculates optimal scheduling using load balancing.
- The Slave simulates processing:
- 2 seconds (optimal)
- 10 seconds (non-optimal)
- The Master receives completion confirmation.
- The Client receives:
Received confirmation message from Master: JOB_COMPLETE:<id>
Implements robust TCP/IP communication using:
PrintWriterBufferedReader
Handles shared resources safely using:
synchronizedblockswait()notifyAll()
This prevents race conditions in job queues.
Each network connection has dedicated Reader and Writer threads, ensuring:
- No blocking on user input
- No blocking on network streams
- No deadlocks
This keeps the system fully asynchronous and responsive.