Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌾 Two Elevators β€” Java Multithreading

A Java multithreading simulation where trucks unload grain into two elevators simultaneously.

Homework #3 for the Multithreading lesson at AIT TR GmbH.


πŸ“‹ Task

Rework the Elevator project from classwork so that:

  • Trucks unload grain into two elevators instead of one
  • During each trip, half the grain goes into elevator #1 and half into elevator #2
  • The Elevator.java class cannot be modified
  • No grain loss β€” every kernel must be accounted for
  • Synchronization must be as efficient as possible (no unnecessary blocking)

πŸ›  Tech Stack

  • Java
  • Multithreading (Runnable, Thread)
  • Synchronization (synchronized, wait / notifyAll)
  • IntelliJ IDEA

πŸ— Architecture

Truck (Thread)
    β”‚
    β”œβ”€β”€ half load ──► ElevatorWorker #1 (Thread) ──► Elevator #1
    β”‚
    └── half load ──► ElevatorWorker #2 (Thread) ──► Elevator #2

Multiple trucks run in parallel. Each truck splits its load exactly in half and notifies both elevator workers. Both halves are unloaded concurrently β€” neither elevator waits for the other.


πŸ”‘ Key Constraints

  • Elevator.java is read-only β€” the synchronization logic lives entirely in Truck and the worker/dispatcher classes
  • Grain split is exact β€” if the load is odd, one elevator gets load/2 and the other gets load - load/2 (no rounding loss)
  • wait / notifyAll are used to coordinate between trucks and elevator workers without busy-waiting

πŸ“ Project Structure

src/ait/elevator/
β”œβ”€β”€ Elevator.java          # Provided class β€” cannot be edited
β”œβ”€β”€ Truck.java             # Runnable β€” generates grain loads, splits them in half
β”œβ”€β”€ ElevatorWorker.java    # Runnable β€” receives half-loads and adds to its Elevator
└── Main.java              # Entry point β€” creates trucks, workers, starts threads

πŸš€ Getting Started

git clone https://github.com/AOgit/ait-two-elevators.git

Open in IntelliJ IDEA and run Main.java.

The console will show each truck's delivery and the running totals in both elevators. At the end, the sum of both elevators equals the total grain delivered by all trucks.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages