博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
普通Java工程利用注解Spring做周期性任务调度框架搭建
阅读量:4111 次
发布时间:2019-05-25

本文共 1254 字,大约阅读时间需要 4 分钟。

需求:

利用注解Spring做周期任务执行操作,这样如果利用spring的task去操作那么会非常简单。

实现:

lib依赖:

org.springframework
spring-core
3.2.0.RELEASE
org.springframework
spring-context
3.2.0.RELEASE
org.springframework
spring-beans
3.2.0.RELEASE

spring配置文件:spring- collect.xml:

main方法加载部分:

import org.springframework.context.support.ClassPathXmlApplicationContext;public class App {	private static ClassPathXmlApplicationContext context = null;	public static ClassPathXmlApplicationContext getContextInstance() {		if (context == null) {			start();		}		if (!context.isRunning()) {			App.context.refresh();			context.registerShutdownHook();		}		return context;	}	private static void start() {		context = new ClassPathXmlApplicationContext(				"classpath:spring-collect.xml");		context.registerShutdownHook();	}	public static void main(String[] args) {		App.start();	}}

业务调度执行部分:

import org.springframework.stereotype.Service;@Service("preJob")public class PreJob {	public void run() {		System.out.println("task execute**********"+System.currentTimeMillis());	}}

 

转载地址:http://ppqsi.baihongyu.com/

你可能感兴趣的文章
codeforces 412 D Dynamic Problem Scoring
查看>>
codeforces -420-B. Okabe and Banana Trees
查看>>
codeforces 420-C. Okabe and Boxes
查看>>
数据结构--线性表的顺序表示及操作
查看>>
UVA 658 It's not a Bug, it's a Feature!
查看>>
Educational Codeforces Round 27-C. Two TVs
查看>>
UVA-1658 Admiral
查看>>
二维几何基础--向量的表示及简单运算
查看>>
向量运算-叉积,点积
查看>>
点-线,线-线
查看>>
That Nice Euler Circuit UVALive - 3263
查看>>
7-9 拯救007
查看>>
7-3 古风排版
查看>>
7-14 最小生成树的唯一性
查看>>
7-11 肿瘤诊断
查看>>
7-8 整除光棍
查看>>
7-16 喊山
查看>>
7-13 地下迷宫探索
查看>>
Tree UVA - 548
查看>>
L2-006. 树的遍历
查看>>