在我的Spring应用程序中,我使用的SchedulerFactoryBean是与Quartz集成.我们将要有群集的Tomcat实例,因此我希望拥有一个集群的Quartz环境,这样相同的作业就不会在不同的Web服务器上同时运行.
为此,我的app-context.xml内容如下:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
<ref bean="simpleTrigger" />
</list>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="overwriteExistingJobs" value="true"/>
<!-- found in applicationContext-data.xml -->
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">SomeBatchScheduler</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<!--<prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>-->
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">25</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
一切都运行良好,除了当我尝试删除或更改触发器,然后重新启动我的应用程序时,旧的触发器仍然保留在数据库中,仍然运行.我不希望这样,我只是希望在app停止(或重新启动)时删除它们.我将overwriteExistingJobs属性的值设置为true,因为我认为这就是它所做的.
有任何想法吗?我只想使用数据库进行聚类,而不是任何类型的持久性.
早在2007年,我读到了一篇关于Joshua Blochs对"构建器模式"的文章,以及如何修改它以改进构造函数和setter的过度使用,特别是当一个对象具有大量属性时,其中大多数是可选的.这里有一个关于这种设计模式的简短摘要[http://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html].
我喜欢这个想法,并且从那时起就一直在使用它.它的问题,虽然从客户的角度来看它非常干净和漂亮,实现它可能是一个痛苦的屁股!对象中有许多不同的位置,其中单个属性是引用,因此创建对象,添加新属性需要花费大量时间.
所以......我有个主意.首先,Joshua Bloch风格的一个示例对象:
乔什布洛赫风格:
public class OptionsJoshBlochStyle {
private final String option1;
private final int option2;
// ...other options here <<<<
public String getOption1() {
return option1;
}
public int getOption2() {
return option2;
}
public static class Builder {
private String option1;
private int option2;
// other options here <<<<<
public Builder() {
}
public Builder option1(String option1) {
this.option1 = option1;
return this;
}
public Builder option2(int option2) {
this.option2 = option2;
return this;
}
public …Run Code Online (Sandbox Code Playgroud)