嗨,我有以下代码:
public Item get(int id)
{
Item i = null;
for(Worker w : workers)
{
w.get(id, i); // Several threads start reading that item from data sources
}
while(i == null) // Loop until item is found
{
// this.pause(); there should be a pause but it's not a thread, so I can't do it.
}
return i;
}
我认为应该有更好的方法,没有那个空循环。
涉及暂停获取功能并仅在其中一名工人通知时恢复的事情。