springboot 启动时执行线程
1.写一个SpringUtil
@Component
public class SpringUtil implements ApplicationContextAware
2.在启动类中可以读取任何bean
SpringApplication.run(Xxx.class, args);
CommonConfig commonConfig = SpringUtil.getBean(Aaa.class);
3.new线程池执行runnable
ExecutorService executorService = Executors.newFixedThreadPool(x); // 以FixedThreadPool为例
executorService.execute(new XxxRunnable();
executorService.shutdown();
------------
健康优化方案: 1.web单独分开; 2.接受c日志的做成一个单独的模块,部署多个,负载均衡; 3.线程应该一直执行,而非10秒一次; 4.取Collections.synchronizedList应该多线程; 5.做预警策略
-->最终线程方案为: 启动时根据业务初始化线程池和线程数, 线程中while(true){hanleQueue(); sleep(10秒);}一直处理BlockQueue; 同时写入做成批量的.
无聊我就学英语

浙公网安备 33010602011771号