package com.telek.springframework.scheduling.quartz;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.StatefulJob;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.MethodInvoker;
/**
* This is a cluster safe Quartz/Spring FactoryBean implementation, which
* produces a JobDetail implementation that can invoke any no-arg method on any
* Class.
* <p>
* Use this Class instead of the MethodInvokingJobDetailBeanFactory Class
* provided by Spring when deploying to a web environment like Tomcat.
* <p>
* <b>Implementation</b><br>
* Instead of associating a MethodInvoker with a JobDetail or a Trigger object,
* like Spring's MethodInvokingJobDetailFactoryBean does, I made the
* [Stateful]MethodInvokingJob, which is not persisted in the database, create
* the MethodInvoker when the [Stateful]MethodInvokingJob is created and
* executed.
* <p>
* A method can be invoked one of several ways:
* <ul>
* <li>The name of the Class to invoke (targetClass) and the static method to
* invoke (targetMethod) can be specified.
* <li>The Object to invoke (targetObject) and the static or instance method to
* invoke (targetMethod) can be specified (the targetObject must be Serializable
* when concurrent=="false").
* <li>The Class and static Method to invoke can be specified in one property
* (staticMethod). example: staticMethod =
* "example.ExampleClass.someStaticMethod" <br>
* <b>Note:</b> An Object[] of method arguments can be specified (arguments),
* but the Objects must be Serializable if concurrent=="false".
* </ul>
* <p>
* I wrote MethodInvokingJobDetailFactoryBean, because Spring's
* MethodInvokingJobDetailFactoryBean does not produce Serializable JobDetail
* objects, and as a result cannot be deployed into a clustered environment like
* Tomcat (as is documented within the Class).
* <p>
* <b>Example</b> <code>
* <ul>
* <bean id="<i>exampleTrigger</i>" class="org.springframework.scheduling.quartz.CronTriggerBean">
* <ul>
<i><!-- Execute example.ExampleImpl.fooBar() at 2am every day --></i><br>
<property name="<a href="http://www.opensymphony.com/quartz/api/org/quartz/CronTrigger.html">cronExpression</a>" value="0 0 2 * * ?" /><br>
<property name="jobDetail">
<ul>
<bean class="frameworkx.springframework.scheduling.quartz.<b>MethodInvokingJobDetailFactoryBean</b>">
<ul>
<property name="concurrent" value="<i>false</i>"/><br>
<property name="targetClass" value="<i>example.ExampleImpl</i>" /><br>
<property name="targetMethod" value="<i>fooBar</i>" />
</ul>
</bean>
</ul>
</property>
</ul>
</bean>
<p>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<ul>
<property name="triggers">
<ul>
<list>
<ul>
<ref bean="<i>exampleTrigger</i>" />
</ul>
</list>
</ul>
</property>
</ul>
</bean>
</ul>
* </code> In this example we created a MethodInvokingJobDetailFactoryBean,
* which will produce a JobDetail Object with the jobClass property set to
* StatefulMethodInvokingJob.class (concurrent=="false"; Set to
* MethodInvokingJob.class when concurrent=="true"), which will in turn invoke
* the static <code>fooBar</code>() method of the "
* <code>example.ExampleImpl</code>" Class. The Scheduler is the heart of the
* whole operation; without it, nothing will happen.
* <p>
* For more information on <code>cronExpression</code> syntax visit <a
* href="http://www.opensymphony.com/quartz/api/org/quartz/CronTrigger.html"
* >http://www.opensymphony.com/quartz/api/org/quartz/CronTrigger.html</a>
*
* @author Stephen M. Wick
*
* @see #afterPropertiesSet()
*/
public class MethodInvokingJobDetailFactoryBean implements FactoryBean, BeanNameAware, InitializingBean {
private Log logger = LogFactory.getLog(getClass());
/**
* The JobDetail produced by the <code>afterPropertiesSet</code> method of
* this Class will be assigned to the Group specified by this property.
* Default: Scheduler.DEFAULT_GROUP
*
* @see #afterPropertiesSet()
* @see Scheduler#DEFAULT_GROUP
*/
private String group = Scheduler.DEFAULT_GROUP;
/**
* Indicates whether or not the Bean Method should be invoked by more than
* one Scheduler at the specified time (like when deployed to a cluster,
* and/or when there are multiple Spring ApplicationContexts in a single
* JVM<i> - Tomcat 5.5 creates 2 or more instances of the DispatcherServlet
* (a pool), which in turn creates a separate Spring ApplicationContext for
* each instance of the servlet</i>)
* <p>
* Used by <code>afterPropertiesSet</code> to set the JobDetail.jobClass to
* MethodInvokingJob.class or StatefulMethodInvokingJob.class when true or
* false, respectively. Default: true
*
* @see #afterPropertiesSet()
*/
private boolean concurrent = true;
/**
* Used to set the JobDetail.durable property. Default: false
* <p>
* Durability - if a job is non-durable, it is automatically deleted from
* the scheduler once there are no longer any active triggers associated
* with it.
*
* @see <a
* href="http://www.opensymphony.com/quartz/wikidocs/TutorialLesson3.html">http://www.opensymphony.com/quartz/wikidocs/TutorialLesson3.html</a>
* @see #afterPropertiesSet()
*/
private boolean durable = false;
/**
* Used by <code>afterPropertiesSet</code> to set the JobDetail.volatile
* property. Default: false
* <p>
* Volatility - if a job is volatile, it is not persisted between re-starts
* of the Quartz scheduler.
* <p>
* I set the default to false to be the same as the default for a Quartz
* Trigger. An exception is thrown when the Trigger is non-volatile and the
* Job is volatile. If you want volatility, then you must set this property,
* and the Trigger's volatility property, to true.
*
* @see <a
* href="http://www.opensymphony.com/quartz/wikidocs/TutorialLesson3.html">http://www.opensymphony.com/quartz/wikidocs/TutorialLesson3.html</a>
* @see #afterPropertiesSet()
*/
private boolean volatility = false;
/**
* Used by <code>afterPropertiesSet</code> to set the
* JobDetail.requestsRecovery property. Default: false<BR>
* <p>
* RequestsRecovery - if a job "requests recovery", and it is executing
* during the time of a 'hard shutdown' of the scheduler (i.e. the process
* it is running within crashes, or the machine is shut off), then it is
* re-executed when the scheduler is started again. In this case, the
* JobExecutionContext.isRecovering() method will return true.
*
* @see <a
* href="http://www.opensymphony.com/quartz/wikidocs/TutorialLesson3.html">http://www.opensymphony.com/quartz/wikidocs/TutorialLesson3.html</a>
* @see #afterPropertiesSet()
*/
private boolean shouldRecover = false;
/**
* A list of names of JobListeners to associate with the JobDetail object
* created by this FactoryBean.
*
* @see #afterPropertiesSet()
**/
private String[] jobListenerNames;
/**
* The name assigned to this bean in the Spring ApplicationContext. Used by
* <code>afterPropertiesSet</code> to set the JobDetail.name property.
*
* @see afterPropertiesSet()
* @see JobDetail#setName(String)
**/
private String beanName;
/**
* The JobDetail produced by the <code>afterPropertiesSet</code> method, and
* returned by the <code>getObject</code> method of the Spring FactoryBean
* interface.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
在数据库中导入附件中的tables_mysql.sql表,将本web项目导入(jar包已经附带),修改项目中的quartz.properties配置文件中的连接数据库信息,将项目部署到tomcat服务器上。本次定时规则为每分钟的6秒倍数在控制台输出一句helloWorld与当前时间。亲测通过可用。
资源推荐
资源详情
资源评论



























收起资源包目录





















































共 31 条
- 1

「已注销」
- 粉丝: 27
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 医学院校计算机专业课程体系构建的探索与实践.docx
- 开题报告项目管理系统设计.pdf
- 最新最专业的企业网站推广方案.doc
- 计算机网络课程设计说明书兰州市第九中学校园网组建方案.doc
- 网络销售实习报告1000字.docx
- 国际项目管理专业资质认证IPMP试题概论.doc
- 工业互联网体系架构.doc
- 海赋国际网络营销方案.pptx
- 组合投资风险与收益与其MATLAB实现.doc
- GOSP-硬件开发资源
- 嵌入式系统期末考试试卷.doc
- 软件学院软件工程领域代码.doc
- 基于Android手机蓝牙控制的智能小车设计.doc
- 电子商务公司的口号.doc
- 网络营销战略计划.pptx
- 三菱FX2N系列PLC.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页