Scheduled多任务的冲突解决

2024-02-20 12:20

本文主要是介绍Scheduled多任务的冲突解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


/*** @author gaoshanshan** @Scheduled多任务的冲突解决* @date 2022/1/7*/
@Configuration
@EnableAsync
public class TaskScheduleConfig {private static final int corePoolSize = 10; // 默认线程数private static final int maxPoolSize = 100; // 最大线程数private static final int keepAliveTime = 10; // 允许线程空闲时间(单位:默认为秒),十秒后就把线程关闭private static final int queueCapacity = 200; // 缓冲队列数private static final String threadNamePrefix = "it`s-threadDemo-"; // 线程池名前缀@Bean("threadPoolTaskExecutor")public ThreadPoolTaskExecutor getDemoThread(){ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();executor.setCorePoolSize(corePoolSize);executor.setMaxPoolSize(maxPoolSize);executor.setQueueCapacity(keepAliveTime);executor.setKeepAliveSeconds(queueCapacity);executor.setThreadNamePrefix(threadNamePrefix);//线程池拒绝任务的处理策略executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//初始化executor.initialize();return executor;}
}

定时任务写法


/*** @author gaoshanshan* @date 2022/1/7*/
@Component
public class SchedulerTaskController {private Logger logger= LoggerFactory.getLogger(SchedulerTaskController.class);private static final SimpleDateFormat dateFormat=new SimpleDateFormat("HH:mm:ss");private int count=0;@Scheduled(cron="0/1 * * * * ?")@Async("threadPoolTaskExecutor")public void process(){logger.info("英文:this is scheduler task runing "+(count++));}@Scheduled(fixedRate = 6000)@Async("threadPoolTaskExecutor")public void currentTime(){logger.info("中文:现在时间"+dateFormat.format(new Date()));}@Scheduled(fixedRate = 1000)@Async("threadPoolTaskExecutor")public void currentTime2(){logger.info("中文--------:现在时间"+dateFormat.format(new Date()));}@Scheduled(fixedDelay = 1000)@Async("threadPoolTaskExecutor")public void currentTime3(){logger.info("中文>>>>>>>>:现在时间"+dateFormat.format(new Date()));}
}

这篇关于Scheduled多任务的冲突解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/728195

相关文章

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

kali linux 无法登录root的问题及解决方法

《kalilinux无法登录root的问题及解决方法》:本文主要介绍kalilinux无法登录root的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录kali linux 无法登录root1、问题描述1.1、本地登录root1.2、ssh远程登录root2、

SpringBoot应用中出现的Full GC问题的场景与解决

《SpringBoot应用中出现的FullGC问题的场景与解决》这篇文章主要为大家详细介绍了SpringBoot应用中出现的FullGC问题的场景与解决方法,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录Full GC的原理与触发条件原理触发条件对Spring Boot应用的影响示例代码优化建议结论F

Pyserial设置缓冲区大小失败的问题解决

《Pyserial设置缓冲区大小失败的问题解决》本文主要介绍了Pyserial设置缓冲区大小失败的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录问题描述原因分析解决方案问题描述使用set_buffer_size()设置缓冲区大小后,buf

PyInstaller打包selenium-wire过程中常见问题和解决指南

《PyInstaller打包selenium-wire过程中常见问题和解决指南》常用的打包工具PyInstaller能将Python项目打包成单个可执行文件,但也会因为兼容性问题和路径管理而出现各种运... 目录前言1. 背景2. 可能遇到的问题概述3. PyInstaller 打包步骤及参数配置4. 依赖

解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'

《解决SpringBoot启动报错:Failedtoloadpropertysourcefromlocationclasspath:/application.yml问题》这篇文章主要介绍... 目录在启动SpringBoot项目时报如下错误原因可能是1.yml中语法错误2.yml文件格式是GBK总结在启动S

idea maven编译报错Java heap space的解决方法

《ideamaven编译报错Javaheapspace的解决方法》这篇文章主要为大家详细介绍了ideamaven编译报错Javaheapspace的相关解决方法,文中的示例代码讲解详细,感兴趣的... 目录1.增加 Maven 编译的堆内存2. 增加 IntelliJ IDEA 的堆内存3. 优化 Mave

如何解决mmcv无法安装或安装之后报错问题

《如何解决mmcv无法安装或安装之后报错问题》:本文主要介绍如何解决mmcv无法安装或安装之后报错问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mmcv无法安装或安装之后报错问题1.当我们运行YOwww.chinasem.cnLO时遇到2.找到下图所示这里3.

浅谈配置MMCV环境,解决报错,版本不匹配问题

《浅谈配置MMCV环境,解决报错,版本不匹配问题》:本文主要介绍浅谈配置MMCV环境,解决报错,版本不匹配问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录配置MMCV环境,解决报错,版本不匹配错误示例正确示例总结配置MMCV环境,解决报错,版本不匹配在col

Feign Client超时时间设置不生效的解决方法

《FeignClient超时时间设置不生效的解决方法》这篇文章主要为大家详细介绍了FeignClient超时时间设置不生效的原因与解决方法,具有一定的的参考价值,希望对大家有一定的帮助... 在使用Feign Client时,可以通过两种方式来设置超时时间:1.针对整个Feign Client设置超时时间