Vous êtes sur la page 1sur 6

Disclaimer: A report submitted to Dublin City University, School of Computing for module

CA463: Concurrent Programming, 2009/2010. I hereby certify that the work presented and
the material contained herein is my own except where explicitly stated references to other material
are made.

The Elevator Problem

Eoin Costelloe

CA463: Concurrent Programming


This system simulates an elevator in an airport. There will be ten floors and the maximum
weight allowed is 1000kg. This elevator will sleep when not needed, will be able to deal with
multiple people waiting for the elevator and multiple people in the elevator waiting for a
Features of the elevator will include:
• only moving to floors that people are waiting at or trying to get to
• sleeping at the middle floor when not needed

This system supports mutual exclusion and absence of deadlock for all attributes of the
elevator object changed by people and the elevator. Eventually the elevator will process every
person proves absence of starvation. This system does not define any specific fairness to people
waiting on the elevator.
Design Plan:


An elevator is unique by the amount of floors it manages and the maximum weight of the
elevator. The system represents an elevator as follows:
• contains number of floors, current floor and whether going up or down to define the
elevators current direction and floor.
• contains the weight of the elevator and the maximum weight to limit the weight of people in
the elevator.
• an array of people waiting for the elevator and an array of people in the elevator waiting for
their destination. Each floor is represented by an element in the list. The amount of people
waiting is represented by the number in the element.
• a condition to wake up the elevator if it is asleep. This is signalled when a person waits for
an elevator
• a condition that the elevator has arrived at a floor. This allows people who are waiting for
the elevator to wake up and check if the elevator is on their floor and there is room so they
can try and enter.
• contains whether the doors to the elevator are open or not. This means people can only enter
the elevator when the doors are open
• contains whether more people need the elevator. This allows the thread to finish normally by
making this false rather than killing the thread mid process.

The elevator moves floors first by sleeping for 100 milliseconds which represents the
transition between floors. Depending on the elevators previous direction, either up or down, it will
prioritize people waiting for the elevator to go in that direction. The elevator will change direction if
the elevator is no longer needed in that direction. If the elevator is not needed in either direction, the
elevator moves to the middle floor which is the optimal floor for when it is needed next.
When the elevator reaches a floor, the elevator opens the doors, notifies the people that the
elevator has arrived, keeps the doors open for 20 milliseconds and then closes the doors.


Every person thread sleeps until their arrival time. This simulates people arriving at different
times for the elevator. The person then notifies that they are waiting for the elevator on their floor.
When the elevator arrives, they try and enter the elevator. They cannot enter the elevator if by doing
so it would be too heavy. When the elevator reaches their destination floor, they try and exit the
Interface Design:
After the program starts there is no user input. The program finishes when all people have
been processed and moved to their specified floor. When a person arrives at the elevator, they will
print out their state. When an elevator moves floor, they will print their state and any changes to
people on that floor.
The interface to the program is completely command prompt based. The program takes one
argument which is the amount of people waiting on the elevator. An example execution of the
program would be “java -jar CA463_Elevator.jar 20 > output.txt”. This outputs the text to output.txt
with 20 people waiting on the elevator.

• Website: http://java.sun.com/, Description: the official java website which documents all
java class API's. This was used for ReentrantLock, Condition and Thread.


Application Programming Interface (API)

UML Diagram:
Sequence Diagram: