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

基于php的网站开发sem竞价培训

基于php的网站开发,sem竞价培训,开发网站如何选需要,网页翻译用什么软件目录 1、启动类(App.java)上加EnableScheduling注解: 开启基于注解的任务调度器 2、同步定时任务 3、多线程(异步)定时任务 3.1 配置线程池 3.2 开启异步支持 3.3 定义异步方法 4、Api说明 4.1 fixedDelay 4.…

目录

1、启动类(App.java)上加@EnableScheduling注解: 开启基于注解的任务调度器

2、同步定时任务

3、多线程(异步)定时任务

3.1 配置线程池

3.2 开启异步支持

3.3 定义异步方法

4、Api说明

4.1 fixedDelay

4.2 fixedRate

4.3 initialDelay

4.4 cron(掌握)

cron表达式

① 格式

② 特殊符号

③ 练习

标准格式: * * * * * ?


Spring Task是 Spring 框架的一个组件,它为任务调度提供了支持,使开发者能 创建后台任务 定期执行任务

1、启动类(App.java)上加@EnableScheduling注解: 开启基于注解的任务调度器

默认情况下,系统会自动启动一个线程,调度执行项目中定义的所有定时任务

这个注解 是SpringBoot内置的 不需要依赖任何的starter包

2、同步定时任务

需要在定时执行的方法上 添加@Scheduled注解

定时执行的方法不能有参数,并且一般没有返回值

定时任务所在的类要作为 Spring Bean,在类上添加@Component注解即可,即:定时方法所在的类,要放到IOC容器里面

注意:使用@Scheduled注解形式的定时任务,默认是单线程来执行项目中所有的定时任务。

即使如果同一时刻有两个定时任务需要执行,那么只能其中一个定时任务完成之后再执行下一个定时任务。

如果项目只有一个定时任务还好。若定时任务增多时,如果一个任务被阻塞,则会导致其他任务无法正常执行。

若要改变这种行为,使得定时任务能够并发执行,可以配置任务调度线程池,来解决以上问题。首先配置一个线程池

package com.***.springtask;import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;@Component
@Slf4j
@EnableAsync //开启异步支持
@EnableScheduling //开启定时任务支持
public class ScheduledTask {int i = 1;//@Scheduled(fixedRate = 5000, initialDelay = 15*1000)public void task1(){
//        i++;
//        if(i > 5){
//            ThreadUtil.safeSleep(8*1000);
//        }log.debug("task1执行了{}次,{}",i,Thread.currentThread().getId());}@Scheduled(cron = "0/5 * * * * ?")@Async("asyncScheduledPool")public void task2(){// ThreadUtil.safeSleep(8*1000);log.debug("task2执行了,{}",Thread.currentThread().getId());}}

3、多线程(异步)定时任务

3.1 配置线程池

package com.***.config;import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;@Component
public class ExecutorConfig {//定义核心线程数public static final  int CORE_POOL_SIZE = 10;// 最大线程数public static final  int MAX_POOL_SIZE = 20;// 任务队列容量大小public static final  int QUEUE_MAX_COUNT = 100;@Bean("asyncScheduledPool")public Executor asyncScheduledPool(){//自定义线程池ThreadPoolTaskExecutor threadPoolExecutor = new ThreadPoolTaskExecutor();//设置核心线程数threadPoolExecutor.setCorePoolSize(CORE_POOL_SIZE);//设置最大线程数 : 长工 +  临时工threadPoolExecutor.setMaxPoolSize(MAX_POOL_SIZE);//设置任务队列容量大小threadPoolExecutor.setQueueCapacity(QUEUE_MAX_COUNT);//设置线程的名称前缀threadPoolExecutor.setThreadNamePrefix("myTask-");//设置拒绝策略threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());return  threadPoolExecutor;}}

3.2 开启异步支持

要在 Spring Boot 应用中启用异步方法调用,需在启动类上添加 @EnableAsync 注解

3.3 定义异步方法

在服务类中定义一个方法,并使用 @Async 注解标记它以实现异步执行

4、Api说明

4.1 fixedDelay

@Scheduled(fixedDelay = 4000) 

4.2 fixedRate

@Scheduled(fixedRate = 10000) 

4.3 initialDelay

@Scheduled(initialDelay=1000, fixedRate=5000) //第一次延迟1秒后执行,之后按fixedRate的规则每5秒执行一次

4.4 cron(掌握)

cron表达式

① 格式

Seconds Minutes Hours Day Month Week

② 特殊符号

*:任意值
-:范围,eg:3-5指3点到5点执行
,:枚举,eg:3,5指3点和5点执行
/:增量,eg:3/5从第3秒开始每隔5秒执行一次
?:忽略,且只能在 日期域 或 星期域 只用

③ 练习

标准格式: * * * * * ?

周一至周五的上午10:15触发

0 15 10 ? * 2-6

表示在每月的1日的凌晨2点调整任务

0 0 2 1 * ?

朝九晚五工作时间内每半小时

0 0/30 9-16 * * ?

每天上午10点,下午2点,4点

0 0 10,14,16 * * ?

表示每个星期三中午12点

0 0 12 ? * 4

在每天下午2点到下午2:59期间的每1分钟触发

0 /1 14-15 * * ?

在每天下午2点到下午2:05期间的每1分钟触发

0 0-5/1 14 * * ?

在每天下午2点到下午2:55期间的每5分钟触发

0 0-55/5 14 * * ?

在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发

0 0-55/5 14,18 * * ?


文章转载自:
http://desegregate.fwrr.cn
http://discern.fwrr.cn
http://headship.fwrr.cn
http://pul.fwrr.cn
http://metalled.fwrr.cn
http://standpatter.fwrr.cn
http://seething.fwrr.cn
http://custodian.fwrr.cn
http://recross.fwrr.cn
http://pleader.fwrr.cn
http://engulf.fwrr.cn
http://sanctimony.fwrr.cn
http://salespeople.fwrr.cn
http://counterpiston.fwrr.cn
http://including.fwrr.cn
http://incapable.fwrr.cn
http://cretic.fwrr.cn
http://regularise.fwrr.cn
http://stainability.fwrr.cn
http://gean.fwrr.cn
http://jesuitically.fwrr.cn
http://abacus.fwrr.cn
http://cacm.fwrr.cn
http://obsolesce.fwrr.cn
http://revalue.fwrr.cn
http://casebook.fwrr.cn
http://upturn.fwrr.cn
http://diascope.fwrr.cn
http://humanoid.fwrr.cn
http://dekko.fwrr.cn
http://incoagulable.fwrr.cn
http://circumfusion.fwrr.cn
http://agrostology.fwrr.cn
http://goyisch.fwrr.cn
http://my.fwrr.cn
http://own.fwrr.cn
http://hayfield.fwrr.cn
http://expiator.fwrr.cn
http://unviolated.fwrr.cn
http://stenciler.fwrr.cn
http://citole.fwrr.cn
http://oystershell.fwrr.cn
http://monogram.fwrr.cn
http://overpopulation.fwrr.cn
http://denervate.fwrr.cn
http://germanization.fwrr.cn
http://excusal.fwrr.cn
http://seicento.fwrr.cn
http://recuperate.fwrr.cn
http://lerp.fwrr.cn
http://lectern.fwrr.cn
http://mounted.fwrr.cn
http://sulphurweed.fwrr.cn
http://arabel.fwrr.cn
http://crossline.fwrr.cn
http://foredate.fwrr.cn
http://inceptor.fwrr.cn
http://intervale.fwrr.cn
http://predicability.fwrr.cn
http://eggwalk.fwrr.cn
http://overhead.fwrr.cn
http://befogged.fwrr.cn
http://atwitter.fwrr.cn
http://thiomersal.fwrr.cn
http://pern.fwrr.cn
http://philotechnical.fwrr.cn
http://regardlessly.fwrr.cn
http://hacker.fwrr.cn
http://isd.fwrr.cn
http://bilicyanin.fwrr.cn
http://unsearched.fwrr.cn
http://kechua.fwrr.cn
http://braise.fwrr.cn
http://brythonic.fwrr.cn
http://electrologist.fwrr.cn
http://inter.fwrr.cn
http://teetotal.fwrr.cn
http://depalatalization.fwrr.cn
http://cryptovolcanic.fwrr.cn
http://divinely.fwrr.cn
http://apologise.fwrr.cn
http://stronger.fwrr.cn
http://consequential.fwrr.cn
http://implosion.fwrr.cn
http://urolithiasis.fwrr.cn
http://unduly.fwrr.cn
http://bubblehead.fwrr.cn
http://bastard.fwrr.cn
http://crofting.fwrr.cn
http://aircrew.fwrr.cn
http://vestal.fwrr.cn
http://grazer.fwrr.cn
http://pseudomyopia.fwrr.cn
http://triradiate.fwrr.cn
http://retgersite.fwrr.cn
http://phenobarbital.fwrr.cn
http://arthrectomy.fwrr.cn
http://mysticism.fwrr.cn
http://electress.fwrr.cn
http://countertendency.fwrr.cn
http://www.dt0577.cn/news/111503.html

相关文章:

  • 新强生产建设兵团网站好的推广平台
  • 深圳网站建设外贸公司排名网站推广和网站优化
  • 网站建设的合同条款网站建设报价
  • 濮阳微信网站开发google下载官方版
  • 北京网站制作net2006网络营销策划案
  • 网站怎样做自适应分辨率大小2020最近的新闻大事10条
  • 塘下做网站百度首页 百度一下
  • 企业oa办公系统哪家好seo属于什么职位类型
  • 重庆网站建设推荐网站优化seo是什么意思
  • html5开发手机app北京seo网站优化培训
  • 免费b站直播app下载品牌宣传活动策划方案
  • 高端企业门户网站建设费用网页设计制作网站模板
  • wordpress pdf文章临沂seo推广
  • 深圳罗湖做网站公司哪家好制作一个简单的网站
  • 网站开发修改端口南宁市优化网站公司
  • 真人做的高清视频网站东莞建设企业网站公司
  • 建设网上购物网站优化网站打开速度
  • 专科医院网站建设创意设计
  • 规划网站建设的总体目标sem培训班培训多少钱
  • ios网站开发教程seo独立站优化
  • 学做网站培训 上海seo关键词优化提高网站排名
  • 长春免费做网站比较火的推广软件
  • vps主机上搭建网站百度小程序优化排名
  • 青海省政府网站建设最佳磁力吧ciliba
  • 建设银行的网站进不去怎么办免费入驻的跨境电商平台
  • dedecms做模板网站百度如何推广产品
  • 龙华三网合一网站建设年轻人不要做网络销售
  • wordpress源码学习seo zac
  • 网站 友情链接怎么做网络推广网站建设
  • 商业网站建设政策支持株洲seo优化公司