Java 类org.springframework.core.task.support.TaskExecutorAdapter 实例源码

项目:lams    文件:ConcurrentTaskExecutor.java   
/**
 * 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);
    }
}
项目:lams    文件:AsyncExecutionAspectSupport.java   
/**
 * Determine the specific executor to use when executing the given method.
 * @return the executor to use (or {@code null}, but just if no default executor has been set)
 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor executorToUse = this.defaultExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
                    " to access qualified executor '" + qualifier + "'");
            executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                    this.beanFactory, Executor.class, qualifier);
        }
        else if (executorToUse == null) {
            return null;
        }
        executor = (executorToUse instanceof AsyncTaskExecutor ?
                (AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
        this.executors.put(method, executor);
    }
    return executor;
}
项目:spring4-understanding    文件:AsyncExecutionAspectSupport.java   
/**
 * 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 has been set)
 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor executorToUse = this.defaultExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            if (this.beanFactory == null) {
                throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
                        " to access qualified executor '" + qualifier + "'");
            }
            executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                    this.beanFactory, Executor.class, qualifier);
        }
        else if (executorToUse == null) {
            return null;
        }
        executor = (executorToUse instanceof AsyncListenableTaskExecutor ?
                (AsyncListenableTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
        this.executors.put(method, executor);
    }
    return executor;
}
项目:spring4-understanding    文件:ConcurrentTaskExecutor.java   
/**
 * 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);
    }
}
项目:my-spring-cache-redis    文件:ConcurrentTaskExecutor.java   
/**
 * 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);
    }
}
项目:spring    文件:ConcurrentTaskExecutor.java   
/**
 * 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);
    }
}
项目:class-guard    文件:AsyncExecutionAspectSupport.java   
/**
 * Determine the specific executor to use when executing the given method.
 * @return the executor to use (or {@code null}, but just if no default executor has been set)
 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor executorToUse = this.defaultExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
                    " to access qualified executor '" + qualifier + "'");
            executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                    this.beanFactory, Executor.class, qualifier);
        }
        else if (executorToUse == null) {
            return null;
        }
        executor = (executorToUse instanceof AsyncTaskExecutor ?
                (AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
        this.executors.put(method, executor);
    }
    return executor;
}
项目:spring    文件:AsyncExecutionAspectSupport.java   
/**
 * 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;
}
项目:spring-scheduling-sr    文件:ConcurrentTaskExecutor.java   
/**
 * 设置并委托给JDK 1.5的并发执行器。
 * 
 * <p>Specify the JDK 1.5 concurrent executor to delegate to.
 */
public final void setConcurrentExecutor(Executor concurrentExecutor) {
    // 默认使用单线程的执行器服务
    this.concurrentExecutor =
            (concurrentExecutor != null ? concurrentExecutor : Executors.newSingleThreadExecutor());
    this.adaptedExecutor = new TaskExecutorAdapter(this.concurrentExecutor);
}
项目:bandwidth-on-demand    文件:AppComponents.java   
@Bean
public Executor asyncExecutor() {
  Thread.setDefaultUncaughtExceptionHandler((t, e) -> LOGGER.error("Uncaught exception in thread " + t + ": " + e, e));

  ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  executor.setCorePoolSize(1 * Runtime.getRuntime().availableProcessors());
  executor.setMaxPoolSize(2 * Runtime.getRuntime().availableProcessors());
  executor.setQueueCapacity(100000);
  executor.setThreadNamePrefix("BoDExecutor-");
  executor.initialize();

  return new TaskExecutorAdapter(new TransactionAwareExecutor(executor));
}
项目:class-guard    文件:ConcurrentTaskExecutor.java   
/**
 * Specify the JDK 1.5 concurrent executor to delegate to.
 */
public final void setConcurrentExecutor(Executor concurrentExecutor) {
    this.concurrentExecutor =
            (concurrentExecutor != null ? concurrentExecutor : Executors.newSingleThreadExecutor());
    this.adaptedExecutor = new TaskExecutorAdapter(this.concurrentExecutor);
}