Search in sources :

Example 6 with AsyncTaskExecutor

use of org.springframework.core.task.AsyncTaskExecutor in project spring-framework by spring-projects.

the class AsyncExecutionAspectSupport method determineAsyncExecutor.

/**
	 * Determine the specific executor to use when executing the given method.
	 * Should preferably return an {@link AsyncListenableTaskExecutor} implementation.
	 * @return the executor to use (or {@code null}, but just if no default executor is available)
	 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor targetExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            targetExecutor = findQualifiedExecutor(this.beanFactory, qualifier);
        } else {
            targetExecutor = this.defaultExecutor;
            if (targetExecutor == null) {
                synchronized (this.executors) {
                    if (this.defaultExecutor == null) {
                        this.defaultExecutor = getDefaultExecutor(this.beanFactory);
                    }
                    targetExecutor = this.defaultExecutor;
                }
            }
        }
        if (targetExecutor == null) {
            return null;
        }
        executor = (targetExecutor instanceof AsyncListenableTaskExecutor ? (AsyncListenableTaskExecutor) targetExecutor : new TaskExecutorAdapter(targetExecutor));
        this.executors.put(method, executor);
    }
    return executor;
}
Also used : AsyncListenableTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) Executor(java.util.concurrent.Executor) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) AsyncListenableTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) TaskExecutorAdapter(org.springframework.core.task.support.TaskExecutorAdapter)

Aggregations

AsyncTaskExecutor (org.springframework.core.task.AsyncTaskExecutor)6 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)4 Callable (java.util.concurrent.Callable)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Executor (java.util.concurrent.Executor)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 WorkAdapter (javax.resource.spi.work.WorkAdapter)1 WorkEvent (javax.resource.spi.work.WorkEvent)1 WorkException (javax.resource.spi.work.WorkException)1 WorkListener (javax.resource.spi.work.WorkListener)1 WorkRejectedException (javax.resource.spi.work.WorkRejectedException)1 Before (org.junit.Before)1 Test (org.junit.Test)1 AsyncListenableTaskExecutor (org.springframework.core.task.AsyncListenableTaskExecutor)1 TaskExecutor (org.springframework.core.task.TaskExecutor)1 TaskRejectedException (org.springframework.core.task.TaskRejectedException)1 TaskTimeoutException (org.springframework.core.task.TaskTimeoutException)1