Java concurrently generate infinite amount of objects

Viewed 808

So I need to make an elevator simulator, and I was wondering how can I go about continuously generating people to call the elevator. I need this to go on forever. So basically a person is created and calls the elevator. All of these calls are kept track of but I think I need to keep track of the people who are actually on the elevator too.

I have a few classes Person, Elevator, ElevatorCall & ElevatorCallQueue.

  1. In Person I have a run() method which basically makes an Elevator call with the current floor and destination floor and then I have a BlockingQueue that I put the call on. This run method just runs while true.

  2. In ElevatorCall I just have getters and setters for the collection and destination floors

  3. In ElevatorCallQueue, I have variables for MAX_CALLS and numberOfPeople. I have a BlockingQueue<ElevatorCall> queue = new ArrayBlockingQueue<ElevatorCall>(MAX_CALLS) and a List<Person> I add people to the list and I run through the list and start the run() method on each person. Finally I create an elevator and provide the queue, and run it.

  4. In Elevator I have the BlockingQueue<ElevatorCalls>. I have a while(true) here also, and inside it I make an ArrayList<ElevatorCall> and then I use the BlockingQueues drainTo method using the ArrayList<ElevatorCalls> as a parameter. The rest of the run() method basically iterates through the array list and does what an elevator does, so It goes to the first pressed button, checks each floor for people and if it is a destination floor.

Right now I've gotton stuck and dont know where to go from here. I need to some how have People continiously added and calling the elevator, and have the Elevator wait if there is no more calls. Would appreciate it if anybody could help put me in the right direction. Thanks

EDIT

Here is the code to the elevator class as somebody said I should post some code. However I'm not sure what code to post so I thought I'd just put in the entire class

1 Answers
Related