Spring Cloud启动慢Initializing ExecutorService 'taskScheduler'占用三分钟

Spring Cloud:

1.问题:
工作例子,启动时,用了三分钟多,才启动成功,查看日志时间


2019-08-23 10:11:20,702 test INFO  o.s.scheduling.concurrent.ThreadPoolTaskScheduler -> Initializing ExecutorService  'taskScheduler'
2019-08-23 10:11:21,186 test INFO  o.s.ui.freemarker.SpringTemplateLoader -> SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@30186c27: startup date [Fri Aug 23 10:10:37 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@24e802a7] and template loader path [classpath:/templates/]
2019-08-23 10:11:21,187 test INFO  o.s.w.servlet.view.freemarker.FreeMarkerConfigurer -> ClassTemplateLoader for Spring macros added to FreeMarker configuration
2019-08-23 10:14:52,272 test INFO  o.s.b.d.autoconfigure.OptionalLiveReloadServer -> LiveReload server is running on port 35729
2019-08-23 10:14:52,511 test INFO  com.netflix.discovery.DiscoveryClient -> Shutting down DiscoveryClient ...
2019-08-23 10:14:52,622 test INFO  com.netflix.discovery.DiscoveryClient -> Completed shut down of DiscoveryClient
2019-08-23 10:14:53,533 test INFO  o.s.scheduling.concurrent.ThreadPoolTaskScheduler -> Initializing ExecutorService 

2.问题所在

Initializing ExecutorService  'taskScheduler'
下面的
2019-08-23 10:11:21,187 test INFO  o.s.w.servlet.view.freemarker.FreeMarkerConfigurer -> ClassTemplateLoader for Spring macros added to FreeMarker configuration
此处卡住三分钟
2019-08-23 10:14:52,272 test INFO  o.s.b.d.autoconfigure.OptionalLiveReloadServer -> LiveReload server is running on port 35729

时间

2019-08-23 10:11:21,187
2019-08-23 10:14:52,272
耗时了3:31

3.网上找原因

https://blog.csdn.net/sinat_41620463/article/details/82657348

在单体服务启动时,发现了一个问题,在控制台输出到如下信息时启动超级慢,需要等待三分钟左右。

 INFO  | restartedMain | org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler | Initializing ExecutorService  'taskScheduler'

猜了以下原因,这是一个ThreadPollTaskScheduler,应该是一个有关线程池的初始化任务,整个项目中只用了两个地方,Spring Bus 和Zipkin,当把Zipkin的依赖包注释掉后,发现启动一切正常了。

    //服务跟踪功能
    //compile("org.springframework.cloud:spring-cloud-sleuth-zipkin-stream")
    
我用的是Stream通讯方式,http通讯应该是没问题的,问题解决的不彻底,之后会深究。

 

4.我解决的办法

只有排除依赖:    zipkin-autoconfigure-storage-mysql 依赖即可
        <dependency> 
            <groupId>org.springframework.cloud</groupId> 
            <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId> 
            <exclusions> 
                <exclusion> 
                    <groupId>io.zipkin.java</groupId> 
                    <artifactId>zipkin-autoconfigure-storage-mysql</artifactId> 
                </exclusion> 
            </exclusions> 
        </dependency>

5.排除依赖后的日志时间
排除依赖:    zipkin-autoconfigure-storage-mysql 的日志时间
2019-09-11 11:44:05,707 test INFO  o.s.scheduling.concurrent.ThreadPoolTaskScheduler -> Initializing ExecutorService  'taskScheduler'
2019-09-11 11:44:06,224 test INFO  o.s.ui.freemarker.SpringTemplateLoader -> SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@541179e7: startup date [Wed Sep 11 11:43:15 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@29215f06] and template loader path [classpath:/templates/]
2019-09-11 11:44:06,226 test INFO  o.s.w.servlet.view.freemarker.FreeMarkerConfigurer -> ClassTemplateLoader for Spring macros added to FreeMarker configuration
2019-09-11 11:44:07,694 test INFO  com.netflix.discovery.DiscoveryClient -> Shutting down DiscoveryClient ...
2019-09-11 11:44:07,715 test INFO  com.netflix.discovery.DiscoveryClient -> Completed shut down of DiscoveryClient
2019-09-11 11:44:08,765 test INFO  o.s.scheduling.concurrent.ThreadPoolTaskScheduler -> Initializing ExecutorService 

2019-09-11 11:44:06,226 
2019-09-11 11:44:07,694 
不到1秒解决了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值