Search in sources :

Example 1 with TaskExecutorAdapter

use of org.springframework.core.task.support.TaskExecutorAdapter 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)

Example 2 with TaskExecutorAdapter

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

the class ConcurrentTaskExecutor method setConcurrentExecutor.

/**
	 * Specify the {@link java.util.concurrent.Executor} to delegate to.
	 * <p>Autodetects a JSR-236 {@link javax.enterprise.concurrent.ManagedExecutorService}
	 * in order to expose {@link javax.enterprise.concurrent.ManagedTask} adapters for it.
	 */
public final void setConcurrentExecutor(Executor concurrentExecutor) {
    if (concurrentExecutor != null) {
        this.concurrentExecutor = concurrentExecutor;
        if (managedExecutorServiceClass != null && managedExecutorServiceClass.isInstance(concurrentExecutor)) {
            this.adaptedExecutor = new ManagedTaskExecutorAdapter(concurrentExecutor);
        } else {
            this.adaptedExecutor = new TaskExecutorAdapter(concurrentExecutor);
        }
    } else {
        this.concurrentExecutor = Executors.newSingleThreadExecutor();
        this.adaptedExecutor = new TaskExecutorAdapter(this.concurrentExecutor);
    }
}
Also used : TaskExecutorAdapter(org.springframework.core.task.support.TaskExecutorAdapter)

Aggregations

TaskExecutorAdapter (org.springframework.core.task.support.TaskExecutorAdapter)2 Executor (java.util.concurrent.Executor)1 AsyncListenableTaskExecutor (org.springframework.core.task.AsyncListenableTaskExecutor)1 AsyncTaskExecutor (org.springframework.core.task.AsyncTaskExecutor)1 TaskExecutor (org.springframework.core.task.TaskExecutor)1