I am trying to create a fixed size Queue in java, I only want to store maximum 10 objects in the Queue. However, the queue keeps on storing/adding objects and ignoring the if
condition.
my code:
Queue<Customer> sitt = new LinkedList<Customer>();
if(sitt.size() < 10) {
System.out.println("Added");
((LinkedList<Customer>)sitt).offer(cust);
} else {
System.out.println("No space..");
}
I have another Runnable class, and I am running 22 threads. This condition should only add 0-9
objects of Customer class. However, the sitt.size()
even exceed 20. Can anyone tell me what's the problem here? that even the if
condition is being ignored.
P.S: The reason I am using Queue here, is because I have need FIFO.