廃止された EJB 呼び出しがサーバー上で継続することを気にしないのであれば、呼び出し元のスレッドが「自然に」終了することを許可するのではなく、その呼び出しが別のスレッドによって置き換えられたために結果を破棄しないのはなぜですか? サンプルの実装を提供する時間はありませんが、Future
s および関連する Java 並行処理クラスを使用すると、ある程度の成果が得られることに気付くかもしれません。
編集
これに加えて、このようなものでうまくいくかもしれませんが、私にはハックに感じられ、もっとエレガントなソリューションがあると確信しています.
呼び出しスレッド (おそらくボタンの onclick メソッド) で:
AsynchronousResultManager.registerRequest("UNIQUE_IDENTIFIER", runnableExecuteRequest);
は次のregisterRequest
ようになります。
registerClick(String id, Runnable execution) {
AtomicReference ref = executions.get(id); //executions is a Map<String, AtomicReference> created as a a computing map by Guava MapMaker
execution.setReference(ref); //so that the Runnable has a reference to it later
ref.set(execution); //this will overwrite an existing reference to a previous invocation.
//here you need to actually kick off your thread in whatever way works best for you
}
runnable
リクエストを実行する は、次のサブクラスになります。
public abstract class RequestRunnable implements Runnable {
private AtomicReference ref;
public void run() {
doRunInternal(); //actually go off and do the request to the J2EE server
if (this == ref.get()) { //ie if the current runnable is the same as in the reference, we can proceed to actually dispatch the result
dispatchResult(); //this method would do something like add a runnable to the SwingWorkerThread
}
}
protected abstract void doRunInternal();
protected abstract void dispatchResult();
public void setReference(AtomicReference ref) {
this.ref = ref;
}
}
これはおそらくクラッシュして燃えるでしょうが、うまくいけば、お問い合わせの行を示しています...