2

私は java.util.concurrent パッケージを初めて使用し、DB からいくつかの行をフェッチする簡単なメソッドを作成しました。DB 呼び出しがそれを処理するために例外をスローすることを確認しました。しかし、私は例外が私に戻ってくるのを見ていません。代わりに、私のメソッドへの呼び出しは null を返します。

この場合、誰かが私を助けることができますか?これが私のサンプルメソッド呼び出しです

private FutureTask<List<ConditionFact>> getConditionFacts(final Member member) throws Exception {
        FutureTask<List<ConditionFact>> task = new FutureTask<List<ConditionFact>>(new Callable<List<ConditionFact>>() {
            public List<ConditionFact> call() throws Exception {
                return saeFactDao.findConditionFactsByMember(member);
            }
        });
        taskExecutor.execute(task);
        return task;
    }

私はググって、その周りのいくつかのページを見つけました。しかし、それに対する具体的な解決策は見当たりません。専門家が助けてください....

taskExecutor は org.springframework.core.task.TaskExecutor のオブジェクトです

4

1 に答える 1

9

FutureTask は新しいスレッドで実行され、例外が発生した場合はそれをインスタンス フィールドに格納します。例外が発生するのは、実行の結果を尋ねるときだけですExecutionException

FutureTask<List<ConditionFact>> task = getConditionFacts(member);
// wait for the task to complete and get the result:
try {
    List<ConditionFact> conditionFacts = task.get();
}
catch (ExecutionException e) {
    // an exception occurred.
    Throwable cause = e.getCause(); // cause is the original exception thrown by the DAO
}
于 2011-07-06T18:39:28.273 に答える