public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport implements MethodInterceptor, Ordered
AsyncTaskExecutor を使用して、メソッド呼び出しを非同期に処理する AOP アライアンス MethodInterceptor。通常、Async アノテーションとともに使用されます。 ターゲットメソッドシグネチャーに関しては、すべてのパラメーター型がサポートされます。ただし、戻り値の型は void または java.util.concurrent.Future のいずれかに制限されています。後者の場合、プロキシから返される Future ハンドルは、非同期メソッドの実行結果を追跡するために使用できる実際の非同期 Future になります。ただし、ターゲットメソッドは同じシグネチャーを実装する必要があるため、戻り値を渡すだけの一時的な Future ハンドルを返す必要があります(Spring の AsyncResult または EJB 3.1 の javax.ejb.AsyncResult など)。
戻り値の型が java.util.concurrent.Future の場合、実行中にスローされた例外は、呼び出し元がアクセスして管理できます。ただし、void 戻り値型では、そのような例外を送信することはできません。その場合、そのような例外を処理するために AsyncUncaughtExceptionHandler を登録できます。
Spring 3.1.2 以降では、Spring の @Async アノテーションと併せてエグゼキューター修飾がサポートされるため、AnnotationAsyncExecutionInterceptor サブクラスの使用が推奨されます。
Async, AsyncAnnotationAdvisor, AnnotationAsyncExecutionInterceptorDEFAULT_TASK_EXECUTOR_BEAN_NAME, loggerHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| コンストラクターと説明 |
|---|
AsyncExecutionInterceptor(ExecutorSE defaultExecutor) デフォルトの AsyncUncaughtExceptionHandler で新しいインスタンスを作成します。 |
AsyncExecutionInterceptor(ExecutorSE defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) 新しい AsyncExecutionInterceptor を作成します。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected ExecutorSE | getDefaultExecutor(BeanFactory beanFactory) この実装は、コンテキスト内で一意の TaskExecutor Bean を検索するか、それ以外の場合は "taskExecutor" という名前の ExecutorSE Bean を検索します。 |
protected StringSE | getExecutorQualifier(MethodSE method) この実装は、Spring 3.1.2 での互換性のための操作ではありません。 |
int | getOrder() このオブジェクトの順序値を取得します。 |
ObjectSE | invoke(MethodInvocation invocation) 指定されたメソッド呼び出しをインターセプトし、メソッドの実際の呼び出しを正しいタスクエグゼキューターに送信して、呼び出し元にすぐに戻ります。 |
configure, determineAsyncExecutor, doSubmit, findQualifiedExecutor, handleError, setBeanFactory, setExceptionHandler, setExecutorcloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSEpublic AsyncExecutionInterceptor(@Nullable ExecutorSE defaultExecutor)
AsyncUncaughtExceptionHandler で新しいインスタンスを作成します。defaultExecutor - 委譲先の ExecutorSE(通常は Spring AsyncTaskExecutor または ExecutorServiceSE)。4.2.6 以降では、このインターセプターのローカルエグゼキューターが別の方法で構築されます public AsyncExecutionInterceptor(@Nullable ExecutorSE defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler)
AsyncExecutionInterceptor を作成します。defaultExecutor - 委譲先の ExecutorSE(通常は Spring AsyncTaskExecutor または ExecutorServiceSE)。4.2.6 以降では、このインターセプターのローカルエグゼキューターが別の方法で構築されます exceptionHandler - 使用する AsyncUncaughtExceptionHandler@Nullable public ObjectSE invoke(MethodInvocation invocation) throws ThrowableSE
MethodInterceptor の invoke invocation - インターセプトして非同期にするメソッド Future を返す場合は FutureSE。それ以外の場合は null。ThrowableSE - インターセプターまたはターゲットオブジェクトが例外をスローする場合 @Nullable protected StringSE getExecutorQualifier(MethodSE method)
AsyncExecutionAspectSupport の getExecutorQualifier method - エグゼキューター修飾子メタデータをインスペクションするメソッド nullAsyncExecutionAspectSupport.determineAsyncExecutor(Method)@Nullable protected ExecutorSE getDefaultExecutor(@Nullable BeanFactory beanFactory)
TaskExecutor Bean を検索するか、それ以外の場合は "taskExecutor" という名前の ExecutorSE Bean を検索します。どちらも解決できない場合 (たとえば、BeanFactory がまったく構成されていない場合)、デフォルトが見つからない場合は、この実装はローカルで使用するために新しく作成された SimpleAsyncTaskExecutor インスタンスにフォールバックします。AsyncExecutionAspectSupport の getDefaultExecutor beanFactory - デフォルトのエグゼキューター検索に使用する BeanFactorynull AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAMEpublic int getOrder()
Ordered 値が高いほど、優先度は低くなります。結果として、最も低い値を持つオブジェクトが最高の優先度を持ちます(サーブレット load-on-startup の値に多少似ています)。
同じ順序の値は、影響を受けるオブジェクトの任意のソート位置になります。
Ordered の getOrder Ordered.HIGHEST_PRECEDENCE, Ordered.LOWEST_PRECEDENCE