zoukankan      html  css  js  c++  java
  • Spring @Async之四:Aysnc的异步执行的线程池

    ProxyAsyncConfiguration.java源码:

    @Configuration
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
    
        @Bean(name = TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)
        @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
        public AsyncAnnotationBeanPostProcessor asyncAdvisor() {
            Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected");
            AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor();
            Class<? extends Annotation> customAsyncAnnotation = this.enableAsync.getClass("annotation");
            if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) {
                bpp.setAsyncAnnotationType(customAsyncAnnotation);
            }
            if (this.executor != null) {
                bpp.setExecutor(this.executor);
            }
            if (this.exceptionHandler != null) {
                bpp.setExceptionHandler(this.exceptionHandler);
            }
            bpp.setProxyTargetClass(this.enableAsync.getBoolean("proxyTargetClass"));
            bpp.setOrder(this.enableAsync.<Integer>getNumber("order"));
            return bpp;
        }
    
    }

    AbstractAsyncConfiguration.java源码:

        @Autowired(required = false)
        void setConfigurers(Collection<AsyncConfigurer> configurers) {
            if (CollectionUtils.isEmpty(configurers)) {
                return;
            }
            if (configurers.size() > 1) {
                throw new IllegalStateException("Only one AsyncConfigurer may exist");
            }
            AsyncConfigurer configurer = configurers.iterator().next();
            this.executor = configurer.getAsyncExecutor();
            this.exceptionHandler = configurer.getAsyncUncaughtExceptionHandler();
        }

    AsyncDefaultAutoConfiguration.java源码:

    public class AsyncDefaultAutoConfiguration {
    
        @Autowired private BeanFactory beanFactory;
    
        @Configuration
        @ConditionalOnMissingBean(AsyncConfigurer.class)
        @ConditionalOnProperty(value = "spring.sleuth.async.configurer.enabled", matchIfMissing = true)
        static class DefaultAsyncConfigurerSupport extends AsyncConfigurerSupport {
    
            @Autowired private BeanFactory beanFactory;
    
            @Override
            public Executor getAsyncExecutor() {
                return new LazyTraceExecutor(this.beanFactory, new SimpleAsyncTaskExecutor());
            }
        }

     更多的SimpleAsyncTaskExecutor见《spring线程池(同步、异步)

  • 相关阅读:
    同台电脑 多Git账号同时使用
    netty对http协议解析原理解析(转载)
    Netty 线程模型与Reactor 模式
    增量/存量数据按时间维度分组
    网易技术分享:Nginx缓存引发的跨域惨案
    全面剖析Redis Cluster原理和应用
    聊聊阿里社招面试,谈谈“野生”Java程序员学习的道路
    美团点评基于 Flink 的实时数仓建设实践
    美团技术分享:大众点评App的短视频耗电量优化实战
    美团技术分享:美团深度学习系统的工程实践
  • 原文地址:https://www.cnblogs.com/duanxz/p/9438757.html
Copyright © 2011-2022 走看看