package frameworkx.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.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
我做的是 spring + quartz+ mysql and oracle 持久层 ibatis and hibernate 项目用eclipse 导入 不同的数据库 请在数据库运行不同的SQL 脚本 用hibernate 时注意 是什么数据库 hibernate.properties 文件第一二行自行更改数据库类型 如果不能正常运行、欢迎联系我、一起讨论 。
资源推荐
资源详情
资源评论
收起资源包目录
quartz+ibatis+oracle/mysql\quartz+hibernate+oracle/mysql (115个子文件)
SchedulerServiceImpl.class 10KB
JobProcessServlet.class 6KB
MethodInvokingJobDetailFactoryBean.class 5KB
BeanInvokingJobDetailFactoryBean.class 5KB
MethodInvokingJobDetailFactoryBean$MethodInvokingJob.class 3KB
BeanInvokingJobDetailFactoryBean$BeanInvokingJob.class 3KB
QuartzDao.class 3KB
CustomerService.class 2KB
CustomerHibernateDao.class 2KB
SimpleServiceTest.class 2KB
SchedulerService.class 2KB
Customer.class 2KB
CustmerIbatisDao.class 1KB
CustomerHibernateDao$1.class 1KB
SpringBeanService.class 1KB
Constant.class 1KB
MethodInvokingJobDetailFactoryBean$StatefulMethodInvokingJob.class 752B
BeanInvokingJobDetailFactoryBean$StatefulBeanInvokingJob.class 732B
.classpath 661B
org.eclipse.wst.common.component 514B
org.eclipse.wst.jsdt.ui.superType.container 49B
home.css 10KB
theme.css 6KB
admin.css 3KB
default.css 1KB
birt.css 194B
Thumbs.db 10KB
today-bg.gif 1KB
cal.gif 127B
status-bg.gif 116B
title-bg.gif 116B
rowhover-bg.gif 110B
normal-bg.gif 110B
active-bg.gif 89B
hover-bg.gif 89B
dark-bg.gif 85B
menuarrow.gif 49B
spring.jar 2.81MB
hibernate3.jar 2.64MB
aspectjweaver-1.5.2a.jar 1.81MB
ojdbc14.jar 1.47MB
mysql-connector-java-5.1.3-rc-bin.jar 631KB
commons-collections-3.1.jar 546KB
c3p0-0.9.0.4.jar 479KB
javassist-3.4.GA.jar 460KB
quartz-all-1.6.5.jar 451KB
antlr-2.7.6.jar 433KB
standard-1.1.2.jar 384KB
log4j-1.2.15.jar 383KB
ibatis-2.3.0.677.jar 375KB
cglib-nodep-2.1_3.jar 317KB
dom4j-1.6.1.jar 307KB
hibernate-annotations.jar 273KB
ehcache-1.2.3.jar 203KB
commons-lang-2.1.jar 203KB
spring-test.jar 177KB
junit-4.4.jar 158KB
aspectjrt-1.5.2a.jar 112KB
hibernate-commons-annotations.jar 65KB
ejb3-persistence.jar 49KB
commons-logging-1.0.4.jar 37KB
slf4j-api-1.5.6.jar 22KB
jstl-1.1.2.jar 20KB
jta-1.1.jar 13KB
slf4j-log4j12-1.5.6.jar 9KB
MethodInvokingJobDetailFactoryBean.java 20KB
BeanInvokingJobDetailFactoryBean.java 19KB
SchedulerServiceImpl.java 11KB
SchedulerService.java 8KB
JobProcessServlet.java 8KB
QuartzDao.java 2KB
SimpleServiceTest.java 2KB
CustomerService.java 2KB
CustomerHibernateDao.java 1KB
Customer.java 1KB
Constant.java 676B
CustmerIbatisDao.java 676B
SpringBeanService.java 613B
jquery-1.3.2.min.js 56KB
calendar.js 50KB
jquery.form.js 23KB
calendar-setup.js 9KB
calendar-en.js 4KB
calendar-zh_CN.js 4KB
job.js 3KB
.jsdtscope 454B
index1.jsp 10KB
list.jsp 4KB
MANIFEST.MF 39B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 330B
org.eclipse.wst.ws.service.policy.prefs 118B
.project 1KB
quartz.properties 999B
quartz.properties 999B
log4j.properties 948B
log4j.properties 948B
jdbc.properties 864B
jdbc.properties 864B
hibernate.properties 376B
共 115 条
- 1
- 2
资源评论
- yangkangtq2014-05-16这个加载之后,有报错,调试了很久
- wjw_hermit2015-01-08有些问题,还需要自己调试修改
- plqljp2015-01-12确实 下下来需要修改 才能正常运行 不过还是的谢谢
- kangqing2015-01-14有些问题,还需要自己调试修改
qq346448412
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功