I'm making a program with while loops that execute in this manner:
- Main thread enters a while loop.
- Nothing happens in the while loop.
- Thread will stay in the while loop until the condition is satisfied.
- Another thread runs a function that will satisfy said condition.
Here is an example:
while(path != null);
There's another function in the class that will set the path to null, and once that happens the main thread should exit this loop. The other function is called in another thread.
However, the main thread does not exit the loop even when path is set to null. Any suggestions?
CODE:
try
{
for (Node n:realpath)
{
Thread.sleep(100);
actor.walk(n);
}
Thread.sleep(100);
}
catch (InterruptedException ex)
{
Logger.getLogger(VNScreen.class.getName()).log(Level.SEVERE, null, ex);
}
realpath.clear();
path = null;
if(path == null)
System.out.println("NULLED PATH");
volatile.