quartz怎么配置做分页查询

封装通用的Spring3+Struts2+MyBatis3的CRUD+条件分页查询,Spring+Quartz调度,FunctionCharts图像化工具 - 下载频道
- CSDN.NET
&&&&封装通用的Spring3+Struts2+MyBatis3的CRUD+条件分页查询,Spring+Quartz调度,FunctionCharts图像化工具
封装通用的Spring3+Struts2+MyBatis3的CRUD+条件分页查询,Spring+Quartz调度,FunctionCharts图像化工具
封装通用的Spring3+Struts2+MyBatis3的CRUD+条件分页查询,Spring+Quartz调度,FunctionCharts图像化工具
&?xml version=&1.0& encoding=&UTF-8&?&
&beans xmlns=&http://www.springframework.org/schema/beans&
xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&
xmlns:context=&http://www.springframework.org/schema/context&
xmlns:aop=&http://www.springframework.org/schema/aop&
xmlns:tx=&http://www.springframework.org/schema/tx&
xsi:schemaLocation=&http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd&&
&bean id=&temperMonitorTimerJob& class=&cn.sup.cd.listener.TemperatureMonitorTaskJob&&&/bean&
&!-- 政策调度--&
&bean id=&temperMonitorTask& class=&org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean&&
&!-- 调用的类 --&
&property name=&targetObject&&
&ref bean=&temperMonitorTimerJob&/&
&/property&
&!-- 调用类中的方法 --&
&property name=&targetMethod&&
&value&temperatureMonitorTimer&/value&
&/property&
&!-- BOOK定义触发时间
几秒后执行monitor.start.time 每隔monitor.interval.time执行--&
&bean id=&getPolicyTime& class=&org.springframework.scheduling.quartz.CronTriggerBean&&
&property name=&jobDetail&&
&ref bean=&temperMonitorTask&/&
&/property&
&!-- cron表达式 --&
&property name=&cronExpression&&
&value&${monitor.start.time}/${monitor.interval.time} * * * * ?&/value&
&/property&
&!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --&
&bean id=&startQuertz& lazy-init=&false& autowire=&no& class=&org.springframework.scheduling.quartz.SchedulerFactoryBean&&
&property name=&triggers&&
&ref bean=&getPolicyTime&/&
&/property&
若举报审核通过,可奖励20下载分
被举报人:
sungang1120
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
您可能还需要
开发技术下载排行1601人阅读
原创整理不易,转载请注明出处:
代码下载地址:
有两种流行Spring定时器配置:Java的Timer类和OpenSymphony的Quartz。
1.Java Timer定时
首先继承java.util.TimerTask类实现run方法
import java.util.TimerT
public class EmailReportTask extends TimerTask{
public void run() {
在Spring定义
配置Spring定时器
&bean id=&scheduleReportTask& class=&org.springframework.scheduling.timer.ScheduledTimerTask&&
&property name=&timerTask& ref=&reportTimerTask& /&
&property name=&period&&
&value&&/value&
&/property&
timerTask属性告诉ScheduledTimerTask运行哪个。代表24个小时
启动Spring定时器
Spring的TimerFactoryBean负责启动定时任务
&bean class=&org.springframework.scheduling.timer.TimerFactoryBean&&
&property name=&scheduledTimerTasks&&
&list&&ref bean=&scheduleReportTask&/&list&
scheduledTimerTasks里显示一个需要启动的定时器任务的列表。
可以通过设置delay属性延迟启动
&bean id=&scheduleReportTask& class=&org.springframework.scheduling.timer.ScheduledTimerTask&&
&property name=&timerTask& ref=&reportTimerTask& /&
&property name=&period&&
&value&value&
&property name=&delay&&
&value&3600000value&
&/property&
这个任务我们只能规定每隔24小时运行一次,无法精确到某时启动
2.Quartz定时器
首先继承QuartzJobBean类实现executeInternal方法
import org.quartz.JobExecutionC
import org.quartz.JobExecutionE
import org.springframework.scheduling.quartz.QuartzJobB
public class EmailReportJob extends QuartzJobBean{
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
在Spring中定义
&bean id=&reportJob& class=&org.springframework.scheduling.quartz.JobDetailBean&&
&property name=&jobClass&&
&value&EmailReportJobvalue&
&property name=&jobDataAsMap&&
&entry key=&courseService&&
&ref bean=&courseService&/&
&/property&
在这里我们并没有直接声明一个EmailReportJob Bean,而是声明了一个JobDetailBean。这个是Quartz的特点。JobDetailBean是Quartz的org.quartz.JobDetail的子类,它要求通过jobClass属性来设置一个Job对象。
使用Quartz的JobDetail中的另一个特别之处是EmailReportJob的courseService属性是间接设置的。JobDetail的jobDataAsMap属性接受一个Map,包括设置给jobClass的各种属性,当。JobDetailBean实例化时,它会将courseService Bean注入到EmailReportJob 的courseService 属性中。
启动定时器
Quartz的org.quartz.Trigger类描述了何时及以怎样的频度运行一个Quartz工作。Spring提供了两个触发器SimpleTriggerBean和CronTriggerBean。&
SimpleTriggerBean与scheduledTimerTasks类似。指定工作的执行频度,模仿scheduledTimerTasks配置 .
&bean id=&simpleReportTrigger& class=&org.springframework.scheduling.quartz.SimpleTriggerBean&&
&property name=&jobDetail& ref=&reprotJob& /&
&property name=&startDelay&&
&value&360000value&
&property name=&repeatInterval&&
&value&value&
&/property&
startDelay也是延迟1个小时启动
CronTriggerBean指定工作的准确运行时间
&bean id=&cronReportTrigger& class=&org.springframework.scheduling.quartz.CronTriggerBean&&
&property name=&jobDetail& ref=&reprotJob& /&
&property name=&cronExpression&&
&value&0 0 6 * * ?value&
&/property&
属性cronExpression告诉何时触发。最神秘就是cron表达式:
Linux系统的计划任务通常有cron来承担。一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素。从左到右:
1.秒2.分3.小时4.月份中的日期(1-31)5.月份(1-12或JAN-DEC)6.星期中的日期(1-7或SUN-SAT)7.年份()&
每个元素都显示的规定一个值(如6),一个区间(9-12),一个列表(9,11,13)或一个通配符(*)。因为4和6这两个元素是互斥的,因此应该通过设置一个问号(?)来表明不想设置的那个字段,“/”如果值组合就表示重复次数(10/6表示每10秒重复6次)。
启动定时器
&bean class=&org.springframework.scheduling.quartz.SchedulerFactoryBean&&
&property name=&triggers&&
&list&&ref bean=&cronReportTrigger&/&list&
&/property&
triggers属性接受一组触发器。
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1239942次
积分:17817
积分:17817
排名:第222名
原创:440篇
转载:88篇
评论:1067条
阅读:25100
(1)(2)(1)(2)(9)(5)(31)(30)(31)(31)(33)(26)(22)(1)(1)(3)(2)(1)(2)(1)(6)(30)(11)(3)(3)(11)(7)(11)(14)(1)(16)(43)(15)(71)(54)企业定时任务调度器Quartz,定时查询数据库 - 蓝色理想 - ITeye技术网站
博客分类:
&&& 看到楼下各位兄弟的批评指正后,确实对我很有启发,任务如果都以配置的形式出现,在项目中是很利于维护的,所以,稍作修改,呵呵。
首先要做QuartzJob定时任务类了,这个类要实现的是Job接口,然后重写execute方法,方法中就是执行你具体要做的事情了。不过首先需要一个配置文件,里面定义了一些参数,是Quartz的一些配置。配置文件如下
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = QuartzScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 3
org.quartz.threadPool.threadPriority = 5
#===============================================================
#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
org.quartz.plugin.jobInitializer.fileName = conf/quartz_jobs.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 60
即使做成配置,这个类也必须要有,一定会有个Job类,专门做数据分析,有的朋友说配置文件搞定所有,不现实,
好了,这就是配置文件,接下来我们就要做这个计划类了,这个类执行的是去源数据库中查询数据,并插入目标数据库中,并且不允许有重复。代码如下
package com.bj58.job.
import java.sql.C
import java.sql.PreparedS
import java.sql.ResultS
import java.sql.SQLE
import mons.logging.L
import mons.logging.LogF
import org.quartz.J
import org.quartz.JobExecutionC
import org.quartz.JobExecutionE
import com.bj58.job.utils.ConnectionFactory_DB_
import com.bj58.job.utils.ConnectionFactory_DB_
* 定时任务类
* Jun 8, 2010
public class QuartzJob implements Job {
private static final Log log = LogFactory.getLog(Job.class);
private static final String findSql_src = "select PortalId from t_portalinfo";
private static final String findSql_dest = "select userId from t_user";
private static final String insertSql_dest = "insert into t_user(userId) values (?)";
* 执行任务方法
public void execute(JobExecutionContext context) throws JobExecutionException {
Connection conn_db_src = ConnectionFactory_DB_src.getConnection();
Connection conn_db_dest = ConnectionFactory_DB_dest.getConnection();
PreparedStatement pstmt_src =
PreparedStatement pstmt_dest =
ResultSet rs_src =
ResultSet rs_dest =
pstmt_src = conn_db_src.prepareStatement(findSql_src);
rs_src = pstmt_src.executeQuery();
pstmt_dest = conn_db_dest.prepareStatement(findSql_dest);
rs_dest = pstmt_dest.executeQuery();
pstmt_dest = conn_db_dest.prepareStatement(insertSql_dest);
while(rs_dest.next()) { //第二次或第n次入库,第一次入库的话rs_dest没有结果,所以此段操作都不执行
String userId = rs_dest.getString(1);
while (rs_src.next()) {
String protalId = rs_src.getString(1);
if(userId.equals(protalId)) { //如果两个结果相同,则不进行入库
pstmt_dest.setString(1, protalId);
pstmt_dest.execute();
while (rs_src.next()) { //如果是第一次入库
String protalId = rs_src.getString(1);
pstmt_dest.setString(1, protalId);
pstmt_dest.execute();
("存储数据...");
} catch (SQLException e) {
("存储数据出现异常...");
e.printStackTrace();
} finally {
ConnectionFactory_DB_dest.free(rs_dest, pstmt_dest, conn_db_dest);
ConnectionFactory_DB_src.free(rs_src, pstmt_src, conn_db_src);
("数据库连接已经关闭...");
这里一次性查出了源数据库中所有字段,因为源数据库表中的数据最多不会超过10000条,我在做测试的时候,在本机上发现一次查询10W条也不会出现结果集溢出情况,所以这里就忽略这个问题了。
然后需要这么个配置文件quartz_jobs.xml,内容如下
&?xml version="1.0" encoding="UTF-8"?&
&job-detail&
&name&PortalInfoJob&/name&
&group&PortalInfo&/group&
&job-class&com.bj58.portalcrm.web.job.PortalInfoJob&/job-class&
&/job-detail&
&name&PORTALINFO&/name&
&job-name&PortalInfoJob&/job-name&
&job-group&PortalInfo&/job-group&
&cron-expression&0 0 1 * * ?&/cron-expression&
&/trigger&
ok,最后就是web.xml文件配置一下,Quartz提供了个初始化的Servlet,呵呵,内容如下
&?xml version="1.0" encoding="UTF-8"?&
&web-app version="2.4"
xmlns="/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="/xml/ns/j2ee
/xml/ns/j2ee/web-app_2_4.xsd"&
&welcome-file-list&
&welcome-file&index.jsp&/welcome-file&
&/welcome-file-list&
&!-- Quartz配置计划 --&
&servlet-name&QuartzInitializer&/servlet-name&
&servlet-class&org.quartz.ee.servlet.QuartzInitializerServlet&/servlet-class&
&load-on-startup&1&/load-on-startup&
&init-param&
&param-name&config-file&/param-name&
&param-value&/quartz.properties&/param-value&
&/init-param&
&init-param&
&param-name&shutdown-on-unload&/param-name&
&param-value&true&/param-value&
&/init-param&
&/servlet&
&/web-app&
这样就搞定了,
论坛回复 /
(16 / 8087)
不说了,配置全部存数据库,做了个Web界面给用户修改。
很高级,对与我的项目来说没必要。
Foxswily 写道这么用quartz太暴殄天物了,
·使用了JobInitializationPlugin还要手动创建Job,quartz_jobs.xml还有何用?scanInterval = 5& 更是白消耗了
·quartz自带QuartzInitializerListener/QuartzInitializerServlet 何必自己写Servlet启动
别的就不说了...
不手动创建job,如何做数据分析。配置文件可以做数据分析吗?quartz_jobs.xml里面应该只是配置好多个job吧。其他的说的有理
quartz_jobs.xml已经创建+配置job了,代码创建实在没什么必要,分析更是该分离到listener里实现。说起来Quartz对配置这块有点疏忽,问题多多、功能不全...
这么用quartz太暴殄天物了,
·使用了JobInitializationPlugin还要手动创建Job,quartz_jobs.xml还有何用?scanInterval = 5& 更是白消耗了
·quartz自带QuartzInitializerListener/QuartzInitializerServlet 何必自己写Servlet启动
别的就不说了...
不手动创建job,如何做数据分析。配置文件可以做数据分析吗?quartz_jobs.xml里面应该只是配置好多个job吧。其他的说的有理
你是适合做练习的,不是做项目的。
鉴定完毕,做项目不会像你这样弄的,呵呵,我一个配置文件搞定所有东西,哪有你那么多东西呢。
那你分享一下你的配置文件吧,我想看看你的配置文件是怎么做数据分析的。
这么用quartz太暴殄天物了,
·使用了JobInitializationPlugin还要手动创建Job,quartz_jobs.xml还有何用?scanInterval = 5& 更是白消耗了
·quartz自带QuartzInitializerListener/QuartzInitializerServlet 何必自己写Servlet启动
别的就不说了...
貌似web.xml配置下就可以聊
你是适合做练习的,不是做项目的。
鉴定完毕,做项目不会像你这样弄的,呵呵,我一个配置文件搞定所有东西,哪有你那么多东西呢。
LZ贴出代码只是为了分享,而不是为了别的什么。
如果你有更优雅的解决方案为什么不贴出来呢?
chris_zley 写道据说晚上11:00-1:00之间最好不要执行任务,否则可能不执行或者重复执行。。
据说会发生灵异现象
哦,这个。。。
据说晚上11:00-1:00之间最好不要执行任务,否则可能不执行或者重复执行。。
据说会发生灵异现象
据说晚上11:00-1:00之间最好不要执行任务,否则可能不执行或者重复执行。。
没有这个据说吧,我们的服务就是每天晚上11点30分开始做的,2年多了,还没有重复的情况发生。
据说晚上11:00-1:00之间最好不要执行任务,否则可能不执行或者重复执行。。
据说?那凌晨2点呢?
重复执行,有没有证明呢?
fengfeng925
浏览: 52637 次
来自: 北京
麻烦分享一下源代码
楼主麻烦分享一下源代码,谢谢!
楼主,最近在学习netty,能参考一下您的源码吗,zhangj ...
java程序员学习之路http://www.zuidaima. ...
楼主,你好,最近在写rpc框架,觉得你这个很好想借鉴下,能否参 ...java quartz如何查看当前执行任务的线程数-问答-最代码
等java quartz如何查看当前执行任务的线程数
请教下,java quartz如何查看当前执行任务的线程数,我在配置文件中设置的org.quartz.threadPool.threadCount = 100,我想看看我在执行任务时,是否有空余的线程
所有回答列表(5)
过来学习下
把所有quartz放到map里边,就可以监控了呀
@牛哥,指教下
在项目增加javamelody监控插件,有独立后台界面查看线程数。
提供下最简单的思路:可以将当前正在运行的quartz job打印一些信息,比如:Thread.currentThread()的线程信息!
另外可以参考这个:
暂无贡献等级
暂无贡献等级
暂无贡献等级
暂无贡献等级
暂无贡献等级
暂无贡献等级
暂无贡献等级
暂无贡献等级
暂无贡献等级
扫描二维码关注最代码为好友"/>扫描二维码关注最代码为好友

我要回帖

更多关于 联表查询之后做分页 的文章

 

随机推荐