当前位置: 首页 > news >正文

人才市场招聘网站定陶区城乡建设局网站

人才市场招聘网站,定陶区城乡建设局网站,小制作小发明手工初中,长沙关键词优化平台在项目我们会有很多需要在某一特定时刻自动触发某一时间的需求#xff0c;例如我们提交订单但未支付的超过一定时间后需要自动取消订单。 定时任务实现的几种方式#xff1a; Timer#xff1a;java自带的java.util.Timer类#xff0c;使用这种方式允许你调度一个java.util…在项目我们会有很多需要在某一特定时刻自动触发某一时间的需求例如我们提交订单但未支付的超过一定时间后需要自动取消订单。 定时任务实现的几种方式 Timerjava自带的java.util.Timer类使用这种方式允许你调度一个java.util.TimerTask任务。这种方式可以让你的程序按照某一个频度执行但不能在指定时间运行。一般用的较少。 ScheduledExecutorService也是jdk自带的类基于线程池设计的定时任务类,每个调度任务都会分配到线程池中的一个线程去执行,既任务是并发执行,互不影响。 Spring TaskSpring3.0以后自带的task相当于一个轻量级的Quartz但其使用起来比Quartz简单很多。 Quartz一个功能比较强大的的调度器可以让你的程序在指定时间执行也可以按照某一个频度执行配置起来稍显复杂。 下面我们看一下如何通过Scheduled实现SpringBoot 的定时任务。 1. 启用定时任务 在springboot主类增加注解EnableScheduling启用定时任务 import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.scheduling.annotation.EnableScheduling; SpringBootApplicationEnableSchedulingpublic class ScheduledApplication {public static void main(String[] args) { SpringApplication.run(SpringBootScheduledApplication.class, args); }} 2.创建任务类 Slf4jComponentpublic class ScheduledService { Scheduled(cron 0/20 * * * * *) public void scheduled(){ log.info(1使用cron {},System.currentTimeMillis()); } Scheduled(fixedRate 3000) public void scheduled1() { log.info(2使用fixedRate{}, System.currentTimeMillis()); } Scheduled(fixedDelay 3000) public void scheduled2() { log.info(3fixedDelay{},System.currentTimeMillis()); }} 默认为单线程可以看到三个定时任务都已经执行并且使同一个线程中串行执行如果只有一个定时任务这样做肯定没问题当定时任务增多如果一个任务卡死会导致其他任务也无法执行。 3.实现多线程任务 3.1 添加配置类并启用异步事件 ConfigurationEnableAsyncpublic class ScheduledAsyncConfig { private int corePoolSize 20;private int maxPoolSize 500;private int queueCapacity 20; Beanpublic Executor taskExecutor() {ThreadPoolTaskExecutor executor new ThreadPoolTaskExecutor();executor.setCorePoolSize(corePoolSize);executor.setMaxPoolSize(maxPoolSize);executor.setQueueCapacity(queueCapacity);executor.initialize();return executor;}} 3.2修改2.中的定时任务的类或者方法上添加Async​​​​​​​ Slf4jComponentAsyncpublic class ScheduledService { Scheduled(cron 0/20 * * * * *) public void scheduled(){ log.info(1使用cron {},System.currentTimeMillis()); } Scheduled(fixedRate 3000) public void scheduled1() { log.info(2使用fixedRate{}, System.currentTimeMillis()); } Scheduled(fixedDelay 3000) public void scheduled2() { log.info(3fixedDelay{},System.currentTimeMillis()); }}​​​​​​​
http://www.hkea.cn/news/14276460/

相关文章:

  • 广西玉林网站建设正规公司英语做美食网站
  • 江宁滨江网站建设首页设计的公司官网
  • 58同城网站建设推广免费制作头像的网站
  • 专业做苗木的网站制作网页视频教程
  • 做网站后端需要什么语言电商网站如何生成app
  • 下载源码就能建网站吗wordpress主题在手机不展示
  • 八度 网站建设广州抖音seo公司
  • 快速将网站seo手机网站技巧
  • 网站制作好以后怎么管理wordpress文章图片怎么居中
  • 高端品牌网站建设兴田德润在那里设计网站大全下载
  • 网站备案 手印随便小影wordpress主题
  • 权威的南通网站建设wordpress发布失败
  • 商业网站建设的方法龙岩市兼职网
  • dw怎么做百度网站邯郸网站
  • 这几年做那个网站致富国外对网站开发的研究
  • 北京网站百度推广vps网站打开需要身份验证
  • 网站建设及网络营销公司注册网站有安全风险怎么注销
  • 百度手机点击排名工具黑帽seo技术培训
  • 自做建材配送网站网站集约化 建设方案
  • 如何提高网站浏览量平面设计师需要学习什么
  • 怎么样建公司网站wordpress如何添加tdk
  • 网站建设的结论和体会网站设计要求 优帮云
  • 国外的服务器网站pycharm 做网站
  • 苏州网站托管服务器网站打不开
  • vue做社区网站wordpress 模板挂马
  • 石家庄网站托管南充阆中网站建设
  • 预告网站正在建设中网上电商平台
  • 做网站开发 甲方提供资料wordpress博客主题 m1
  • 宜昌十堰网站建设哪家好外贸行业的现状分析及发展趋势
  • 福州公交集团网站建设建设规范文件在哪个网站发布