I have an ArrayList called queue where I store the Customers in a Supermarket as they arrive to the checkout. When they have paid, I remove the first element of the Arraylist (the Customer that was first on the queue), but I don't know how to tell the second one, that now is the first, to proceed to pay. In addition, this Customer should be waiting for an "event".
To sum up, I'm looking for something like a "signal" and "wait".
Here is an outline of what I have:
public class Customer{
public void checkItems(){
//Here goes the code for waiting his turn
//Here goes the code for paying items (already done)
//The next line is how I remove the client of the queue
Globals.checkoutList.get(currentCheckout).queue.remove(0);
Checkout.nextCustomer();
}
}
public class Checkout{
public static void nextCustomer(){
//Here I should tell the next customer that it is his turn
}
}
Regards and thanks.
EDIT: maybe using Exceptions? Help with exceptions will be appreciated too.