Skip to content

sueszli/concurrent-elevators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A super minimal implementation of a thread-pool-executor service / scheduler in Java. The goal is to provide a simple, easy to understand implementation. The implementation is not intended to be used in production, but rather to be used as a learning tool.

Problem

  • There are 7 elevators in a building with 55 floors.

  • Each floor has exactly one button to request an elevator.

  • Elevators have the capacity of carrying an arbitrary, given number of people.

  • Elevators don't change direction and don't stop mid-trip.

  • People can only choose their destination freely, when they are on the ground-floor:

    • up: ground-floor [0] − can only travel to ⟶ non-ground-floor [1;54]
    • down: non-ground-floor [1;54] − can only travel to ⟶ ground-floor [0]
  • The requests are handled globally.

  • The elevator-scheduler assigns a chosen request to an elevator based on some arbitrary algorithm.

  • If there are no elevators available, the request is queued up.

Design decisions

  • Decided to use vanilla Java without any non-default libraries for the sake of simplicity.
  • Got rid of the suggested "up"/"down" directions since they can be inferred from the current floor.
  • Chose a poison-pill approach to terminate the scheduler (also see: this similar implementation)
  • Chose JDK-19 to make use of type inferrence with var and other nifty features.

About

elevators concurrency problem in java

Topics

Resources

License

Stars

Watchers

Forks

Languages