I have been working on a little project with two threads. One generates content and places it in a Queue (in a static context). The other thread runs and waits for content in the queue to do something.
The Issue:
While the second thread is waiting for something to be placed in the queue, it seems to not be running, I will try to show this.
I am just curious is what is happening here.
_slices
is a Queue : Queue<E> _slices = new LinkedList<E>();
Thread 2 run()
:
while ( true ) {
if ( !Main._slices.isEmpty() ) {
System.out.println( "Something in the Queue!" );
} else if ( Main.doneQueuing ) {
break;
}
}
This code above will not do anything once an element is added to the queue.
Now, this code works:
while ( true ) {
System.out.println( "As long as a process is done here it works" );
if ( !Main._slices.isEmpty() ) {
System.out.println( "Something in the Queue!" );
} else if ( Main.doneQueuing ) {
break;
}
}