spring 注解配置定时器
来源:互联网 发布:clojure编程 编辑:程序博客网 时间:2024/04/29 05:02
<pre name="code" class="html"><!-- 自动包扫描配置 --><context:component-scan base-package="com.xx" />
首先配置加上任务注解驱动配置
<task:annotation-driven />
package com.wjxjt.ddt.message.service;import java.util.concurrent.atomic.AtomicLong;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Service;@Servicepublic class TestScheduleService {private AtomicLong atomicLong = new AtomicLong(0);@Scheduled(cron="*/5 * * * * ?") public void job(){System.out.println("定时器"+atomicLong.incrementAndGet());if(atomicLong.longValue()==5l){System.out.println("开始阻塞");try {Thread.sleep(9000000);} catch (InterruptedException e) {e.printStackTrace();}}}}
以上代码spring定时器每隔5秒钟执行,但是如果方法里面死锁或者阻塞了,那么下次5秒钟是不会再执行了,必须等上一次任务执行完成才会继续,下面是运行结果
定时器1定时器2定时器3定时器4定时器5开始阻塞 //再这里就会阻塞,下一次五秒并没有开始任务,必须等sleep完成后才会继续
0 0
- spring 注解配置定时器
- Spring配置定时器任务注解
- spring--简单实现定时器(配置+注解)
- spring定时器Task注解方式配置
- Spring @Scheduled 注解实现定时器调度配置
- spring自带定时器@Scheduled注解配置
- spring MVC定时器注解配置说明
- Spring注解定时器@Scheduled
- spring注解定时器
- Spring 注解 定时器
- spring定时器基于注解
- Spring定时器-注解
- Spring 配置定时器(注解+xml)方式—整理
- Spring定时器的配置(注解+xml)方式
- Spring 定时器配置 基于注解 (使用 Spring4)
- java spring注解定时器应用
- java spring注解定时器应用
- java spring定时器(注解)
- iOS CoreBluetooth 教程蓝牙技术
- java面试之异常捕获
- 中国震惊超算界 ISC13华中科技大学HPL夺冠
- impdp ORA-00001: unique constraint (SYS.I_JOB_JOB) violated
- UVA - 111 History Grading
- spring 注解配置定时器
- WiFi影盘教你解决手机内存 留住一个肾
- jquery插件大全
- 这是我的程序员之路的开始,以此为我以后做一个激励和标志
- c语言整数表示
- Swift 编程语言入门教程
- linq介绍
- android与WEB服务器交互时,如何保证在同一个会话Session中通信
- php从数据库中取二进制流文件转换为图片,图片以二进制流存入数据库实现