我正在编写一个程序,其中while循环以以下方式执行:
- 主线程进入while循环。
- while循环中不会发生任何事情。
- 线程将一直停留在while循环中,直到条件得到满足。
- 另一个线程运行将满足该条件的函数。
这里是一个例子:
while(path != null);
这个类中还有另一个函数会将路径设置为null,一旦发生这种情况,主线程应该退出此循环。另一个函数在另一个线程中被调用。
然而,即使将路径设置为null,主线程仍然没有退出循环。有什么建议吗?
代码:
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");