클래스 중 하나에 주입되는 EJB가 있습니다. EJB에는 주입 된 클래스에서 자원 모니터링을 시작하는 메소드가 있습니다. 모니터 메소드에는 변수 중 하나가 업데이트되면 깨져 있어야하는 while 루프가 있습니다. 코드는 다음과 같이 보입니다 : 내 로그에서상태 변수 EJB의 변수 업데이트
public class MyObject()
{
@EJB
private MyEJB myEjb;
private Collection stuffToMonitor;
public MyObject()
{
//empty
}
public void doSomething()
{
// create collection of stuffToMonitor
myEjb.startMonitoring(stuffToMonitor);
// code that does something
if(conditionsAreMet)
{
myEjb.stopMonitoring();
}
// more code
}
}
@Stateful
public class MyEJB()
{
private volatile boolean monitoringStopped = false;
public MyEJB()
{
//empty
}
public void startMonitoring(Collection stuffToMonitor)
{
int completed = 0;
int total = stuffToMonitor.size();
while(completed < total)
{
// using Futures, track completed stuff in collection
// log the value of this.monitoringStopped
if (this.monitoringStopped)
{
break;
}
}
}
public voide stopMonitoring()
{
this.monitoringStopped = true;
// log the value of this.monitoringStopped
}
}
, 나는 this.monitoringStopped의 값이 stopMonitoring 메소드가 호출 된 후 true
것을 볼 수 있지만, 항상 while 루프에서 false
로 기록합니다.
원래 MyEJB는 상태 비 저장이며 상태가 변경되었으며 변수도 volatile로 변경되었지만 변경 내용은 while 루프에서 선택되지 않았습니다.
monitoringStopped 변수의 업데이트 된 값을 얻기 위해 코드를 가져 오려면 무엇이 누락 되었습니까?