私はjava.util.concurrent
パッケージングに不慣れで、Future
オブジェクトに問題が発生しました。
これはconversationScopedBeanです。
@Inject SomeBean stateFull;
Boolean comp = false, comp1 = false;
public void doSomething(){
stateFull.runProcess();
try {
comp = stateFull.getFuture().get();
System.out.println("Future "+syncEJB.getFuture().get());
updateView();
comp1 = stateFull.getFuture1().get();
System.out.println("Future "+syncEJB.getFuture().get());
updateView();
} catch (InterruptedException ex) {
Logger.getLogger(SynchronizationMB.class.getName()).log(Level.SEVERE, null, ex);
} catch (ExecutionException ex) {
Logger.getLogger(SynchronizationMB.class.getName()).log(Level.SEVERE, null, ex);
}
}
SomeBeanは次のようになります。
@Stateful
public class SomeBean{
@Inject AnotherBean stateLess;
private volatile Future<Boolean> future, future1;
@Asynchronous
public void runProcess(){
future = stateLess.compute();
future1 = stateLess.compute();
}
public Future<Boolean> getFuture() {
return future;
}
public Future<Boolean> getFuture1() {
return future1;
}
}
そしてAnotherBean:
@Stateless
public class AnotherBean{
@Asynchronous
public Future<Boolean> compute() {
boolean result;
System.out.println("--------------");
System.out.println("completed sync");
System.out.println("--------------");
result = true;
return new AsyncResult<Boolean>(result);
}
}
そして今、私の問題に。私はdoSomething()
メソッドを呼び出し、そのドキュメントによれば、 SomeBeanのfutureがAnotherBeanから完了するまでFuture.get()
呼び出す必要があると思います
が、それはただスローし続けます。なぜそれが起こっているのか誰もが知っていますか?runProcess()
comp = stateFull.getFuture().get();
NullPointerException
- - - - - - - - - -編集 - - - - - - - - - - - -
NullPointerが修正されました。今、私は別の問題を抱えています。runProcess()でより多くのメソッドを呼び出すことにより、Somebeanでより多くのFutureオブジェクトを設定したとしましょう。そして、Futureオブジェクトが結果を取得して進行状況を確認するたびに、ページを更新したいと思います。それ、どうやったら出来るの?今私は使用します
private void updateView(){
RequestContext ctx = RequestContext.getCurrentInstance();
ctx.update("mainFrm:info");
}
doSomething()メソッドのすべてのブール値の下にありますが、それは私が望むことをしません。すべてのブール値が一度に表示されます。