项目结构图:

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中的使用的更多相关文章

  1. Quartz 在 Spring 中如何动态配置时间--转

    原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...

  2. velocity模板引擎学习(4)-在standalone的java application中使用velocity及velocity-tools

    通常velocity是配合spring mvc之类的框架在web中使用,但velocity本身其实对运行环境没有过多的限制,在单独的java application中也可以独立使用,下面演示了利用ve ...

  3. 在Activity和Application中使用SharedPreferences存储数据

    1.在Activity中创建SharedPreferences对象及操作方法 SharedPreferences pre=getSharedPreferences("User", ...

  4. Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)

    什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什么任务,但任务的定时是不确定的(是由客户制定).      这样总不能修改配置文件每定制个定时任务就增加一个trigger吧,即便允许客户 ...

  5. struts2标签获取parameter,request,session,application中的值

    http://localhost:8080/demo/index.jsp?flag=kkkk <s:property value="#parameters.flag" /&g ...

  6. 在android.app.Application中定义全局变量

    在Android应用中使用全局变量,除了public的静态变量,还有更优雅的方式是使用android.app.Application. 启动Application时,系统会创建一个PID,即进程ID, ...

  7. Android app图标总是显示默认的机器人图标,且在manifest文件的application中修改无效...

    问题描述:我使用的开发工具是eclipse,Android app默认的图标是一个机器人,如下图所示 现在我要将app的图标修改成另外一个图标: 探索过程: 首先想到修改Manifest文件中的app ...

  8. Quartz在Spring中动态设置cronExpression

    什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什么任务,但任务的定时是不确定的(是由客户制定). 这样总不能修改配置文件每定制个定时任务就增加一个trigger吧,即便允许客户修改配置文 ...

  9. Android Application中的Context和Activity中的Context的异同

    一.Context是什么: 1.Context是维持Android程序中各组件能够正常工作的一个核心功能类,我们选中Context类 ,按下快捷键F4,右边就会出现一个Context类的继承结构图啦, ...

随机推荐

  1. AtCoder Grand Contest 004 C - AND Grid

    题意: 给出一张有紫色点的网格,构造一张红点网格和一张蓝点网格,使红蓝点的交集为紫色点. 保证网格四周没有紫色点. 构造一下,使蓝点和红点能够到每个点. #include<bits/stdc++ ...

  2. A1083. List Grades

    Given a list of N student records with name, ID and grade. You are supposed to sort the records with ...

  3. centos7 上配置Javaweb---MySQL的安装与配置、乱码解决

    上一篇谢了关于jdk和tomcat的安装.今天先更新一下有用的. 1. 不用关闭防火墙,把80端口添加进防火墙的开放端口. firewall-cmd --zone=public --add-port= ...

  4. 【leetcode】 Merge Intervals

    Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given  ...

  5. GO语言的进阶之路-协程和Channel

    GO语言的进阶之路-协程和Channel 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 看过我之前几篇博客小伙伴可能对Golang语言的语法上了解的差不多了,但是,如果想要你的代码 ...

  6. java 中如何声明线程安全的集合 set, map 和list【转】

    线程安全的集合 引用自 http://blog.sina.com.cn/s/blog_508938e10102v1ig.html //make thread-safe list List MyStrL ...

  7. SGU 271 Book Pile

    There is a pile of N books on the table. Two types of operations are performed over this pile: - a b ...

  8. 08-DML(插入、更新、删除)

    1. 插入 (1). 插入完整数据记录 (2). 插入数据记录的一部分 (3). 插入多条记录(MySQL特有的) INSERT INTO table_name (column1,column2,co ...

  9. 浅谈cookie与session的区别

    cookie用的是在客户端保持状态的方案(它是在用户端的会话状态的存贮机制),前端也可以来设置他 所有浏览器都识别,并且会缓存在浏览器中. cookie是以key=value这种键值对的形式保存,每个 ...

  10. 20155301 2016-2017-2 《Java程序设计》第7周学习总结

    20155301 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 1.例如 Compartor<String>byLength=new Compa ...