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

广州天河网站制作seo排名优化方式方法

广州天河网站制作,seo排名优化方式方法,推荐 官网 潍坊网站建设,东莞专业微网站建设价格低在项目我们会有很多需要在某一特定时刻自动触发某一时间的需求,例如我们提交订单但未支付的超过一定时间后需要自动取消订单。 定时任务实现的几种方式: Timer:java自带的java.util.Timer类,使用这种方式允许你调度一个java.util…

在项目我们会有很多需要在某一特定时刻自动触发某一时间的需求,例如我们提交订单但未支付的超过一定时间后需要自动取消订单。

定时任务实现的几种方式:

  • Timer:java自带的java.util.Timer类,使用这种方式允许你调度一个java.util.TimerTask任务。这种方式可以让你的程序按照某一个频度执行,但不能在指定时间运行。一般用的较少。

  • ScheduledExecutorService:也是jdk自带的类;基于线程池设计的定时任务类,每个调度任务都会分配到线程池中的一个线程去执行,既任务是并发执行,互不影响。

  • Spring Task:Spring3.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;
@SpringBootApplication@EnableSchedulingpublic class ScheduledApplication {
    public static void main(String[] args) {        SpringApplication.run(SpringBootScheduledApplication.class, args);    }}

2.创建任务类

@Slf4j@Componentpublic 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 添加配置类并启用异步事件

@Configuration@EnableAsyncpublic 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​​​​​​​

@Slf4j@Component@Asyncpublic 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.mmbaike.com/news/63828.html

相关文章:

  • 东铁匠营网站建设公司武汉软件测试培训机构排名
  • 抖音广告推广优化优化
  • 合肥做网站需要多少钱seo怎么优化网站排名
  • 哪个网站可以接任务做兼职18款禁用看奶app入口
  • 网游网站开发上海网络推广团队
  • html教程pdf钦州seo
  • 简单的网页seo关键字怎么优化
  • 程序员做博彩类的网站犯法吗软文范例100字
  • 搭建网站 软件torrent种子猫
  • 网站营销培训重庆高端seo
  • 海南网络广播电视台直播海南鸡西seo
  • 网站建设作业一键建站
  • 怎么创网站赚钱吗种子搜索引擎torrentkitty
  • wordpress免费虚拟主机白云百度seo公司
  • 做消费信贷网站搜索引擎营销的概念
  • mylife wordpress深圳纯手工seo
  • 东莞 网站制作中国企业100强
  • 山东网站定制策划百度舆情
  • 网络水果有哪些网站可以做怎么建立一个网站
  • 网站建设就业百度知道网页版入口
  • 建设银行网站改手机号搜索引擎优化是什么工作
  • 做百度推广和企业网站那个有效果吗网页在线客服免费版
  • 网页浏览器打不开宁波seo快速优化公司
  • 免费的一级域名申请丈哥seo博客工具
  • 北京建设注册中心网站首页网络营销推广方案案例
  • 常德市网站建设电商平台开发需要多少钱
  • 重庆网站建公司大全西安seo外包
  • 悦然外贸建站网盘app下载
  • 岳阳公司网站开发深圳全网推广效果如何
  • 论坛门户网站开发互联网推广招聘