안녕 작업 I 다음 코드 조각이 :자바 여러 스레드가 하나 개의 필드에
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;
}
내가 더 나은 방법이 있어야한다고 생각, 그 빈 루프 않고 있습니다.
get 기능을 일시 중지하고 작업자 중 한 사람이 알림 만 다시 시작하는 것과 관련된 문제입니다.
이 빈 루프가 작동 할 수 있습니까? – NPE
그 질문이나 진술인가? –
'i'는 코드에서 null이되지 않습니다. 너는'i'가 아니라 근로자에게'null '을 전달한다. –