quartz在application中的使用
项目结构图:

TestMain.java
package com;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory; public class TestMain { public static void main(String[] args) { try {
// 设置quartz.properties的classpath
System.setProperty("org.quartz.properties", "quartz/quartz.properties");
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
MyQuartzJob.java
package task; import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; public class MyQuartzJob implements Job {
private static int num = 0;
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("Hello World! " + num++);
}
}
quartz_jobs.xml
<?xml version='1.0' encoding='utf-8'?>
<quartz xmlns="http://www.opensymphony.com/quartz/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opensymphony.com/quartz/JobSchedulingData
http://www.opensymphony.com/quartz/xml/job_scheduling_data_1_5.xsd"
version="2.0.2"> <!-- 每3秒执行一次 -->
<job>
<job-detail>
<name>MyQuartzJob</name>
<description></description>
<group>Server</group>
<job-class>task.MyQuartzJob</job-class>
<job-data-map allows-transient-data="true" />
</job-detail>
<trigger>
<cron>
<name>MyQuartzJobbTriger</name>
<group>Server</group>
<job-name>MyQuartzJob</job-name>
<job-group>Server</job-group>
<cron-expression>0/3 * * * * ?</cron-expression>
</cron>
</trigger>
</job> </quartz>
quartz.properties
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = TestScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
#å¤çç线ç¨ä¸ªæ°
org.quartz.threadPool.threadCount = 10
#线ç¨ä¼å 级å«ï¼ä¸è¬ä¸º5
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
#============================================================================
# Configure Plugins
#============================================================================
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
# fs notice : the classpath of quartz_jobs.xml
org.quartz.plugin.jobInitializer.fileNames = quartz/quartz_jobs.xml
#妿jobs.xmlä¸åå¨è°åº¦å¨ä¸å·²ç»æçjobï¼true为è¦ç
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
#æ«æjobs.xmlçæ¶é´é´é
org.quartz.plugin.jobInitializer.scanInterval = 60000
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
quartz在application中的使用的更多相关文章
- Quartz 在 Spring 中如何动态配置时间--转
原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...
- velocity模板引擎学习(4)-在standalone的java application中使用velocity及velocity-tools
通常velocity是配合spring mvc之类的框架在web中使用,但velocity本身其实对运行环境没有过多的限制,在单独的java application中也可以独立使用,下面演示了利用ve ...
- 在Activity和Application中使用SharedPreferences存储数据
1.在Activity中创建SharedPreferences对象及操作方法 SharedPreferences pre=getSharedPreferences("User", ...
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什么任务,但任务的定时是不确定的(是由客户制定). 这样总不能修改配置文件每定制个定时任务就增加一个trigger吧,即便允许客户 ...
- struts2标签获取parameter,request,session,application中的值
http://localhost:8080/demo/index.jsp?flag=kkkk <s:property value="#parameters.flag" /&g ...
- 在android.app.Application中定义全局变量
在Android应用中使用全局变量,除了public的静态变量,还有更优雅的方式是使用android.app.Application. 启动Application时,系统会创建一个PID,即进程ID, ...
- Android app图标总是显示默认的机器人图标,且在manifest文件的application中修改无效...
问题描述:我使用的开发工具是eclipse,Android app默认的图标是一个机器人,如下图所示 现在我要将app的图标修改成另外一个图标: 探索过程: 首先想到修改Manifest文件中的app ...
- Quartz在Spring中动态设置cronExpression
什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什么任务,但任务的定时是不确定的(是由客户制定). 这样总不能修改配置文件每定制个定时任务就增加一个trigger吧,即便允许客户修改配置文 ...
- Android Application中的Context和Activity中的Context的异同
一.Context是什么: 1.Context是维持Android程序中各组件能够正常工作的一个核心功能类,我们选中Context类 ,按下快捷键F4,右边就会出现一个Context类的继承结构图啦, ...
随机推荐
- change username on ubuntu.
Below tutorial will show you how to change username in ubuntu 12.04 precise.First,we need login as r ...
- Luogu 2590 [ZJOI2008]树的统计 / HYSBZ 1036 [ZJOI2008]树的统计Count (树链剖分,LCA,线段树)
Luogu 2590 [ZJOI2008]树的统计 / HYSBZ 1036 [ZJOI2008]树的统计Count (树链剖分,LCA,线段树) Description 一棵树上有n个节点,编号分别 ...
- 【POJ3090】Visible Lattice Points
题目大意:求 \[\sum\limits_{i=2}^n\phi(i)\] 题解:利用与埃筛类似的操作,可在 \(O(nlogn)\) 时间求出结果. 代码如下 #include <cstdio ...
- JVM总结(五):JVM字节码执行引擎
JVM字节码执行引擎 运行时栈帧结构 局部变量表 操作数栈 动态连接 方法返回地址 附加信息 方法调用 解析 分派 –“重载”和“重写”的实现 静态分派 动态分派 单分派和多分派 JVM动态分派的实现 ...
- 设计模式---对象创建模式之原型模式(prototype)
一:概念 原型模式(Prototype Pattern) 实际上就是动态抽取当前对象运行时的状态 Prototype模式是一种对象创建型模式,它采取复制原型对象的方法来创建对象的实例.使用Protot ...
- Study 6 —— while循环
语法while 条件: 执行代码... 1. #从0打印到100,每循环一次 +1 count = 0 while count <= 100 : print('Loop: ', count) c ...
- go for range
func main() { var str = "hellow worda" for _, val := range str { fmt.Printf("%q" ...
- 【转】Robot Framework作者建议如何选择自动化测试框架
原文:http://www.infoq.com/cn/news/2012/06/robot-author-suggest-autotest 软件自动化测试,作为手工测试的替代,越来越受到关注.Pekk ...
- 【BZOJ】1443: [JSOI2009]游戏Game
[算法]博弈论+二分图匹配(最大流) [题解]方格图黑白染色得到二分图, 二分图博弈:当起点不属于某个最大匹配时,后手必胜. 问题转化为那些点不属于某个最大匹配. 先找到一个最大匹配,非匹配点加入答案 ...
- Linux 查看服务进程运行时间
Linux 查询服务进程的 运行时间 查看运行时间 ps -eo pid,lstart,etime | grep pid ps -eo pid,lstart,etime | grep 1713 # ...