I would do it differently, this is the basic idea:
class Elevator extends Thread {
NavigableSet<Integer> calls = new ConcurrentSkipListSet<>();
int floor = 1;
@Override
public void run() {
for (;;) {
try {
Thread.sleep(100);
while (calls.higher(floor) != null) {
move(+1);
}
while (calls.lower(floor) != null) {
move(-1);
}
} catch (InterruptedException e) {
}
}
}
void move(int n) throws InterruptedException {
floor += n;
System.out.println("Moving to " + floor);
Thread.sleep(3000);
if (calls.remove(floor)) {
System.out.println("Stopped");
Thread.sleep(3000);
}
}
void call(int floor) {
calls.add(floor);
}
}
test
Elevator e = new Elevator();
e.start();
e.call(2);
e.call(4);
e.call(1);
output
Moving to 2
Stopped
Moving to 3
Moving to 4
Stopped
Moving to 3
Moving to 2
Moving to 1
Stopped