gpt4 book ai didi

java - 为什么 quartz 不重新启 Action 业?

转载 作者:行者123 更新时间:2023-11-30 03:36:18 27 4
gpt4 key购买 nike

我正在做一个Web应用程序,使用Spring 3.0.5.RELEASE +quartz 1.8.6,并使用MySQL 5.5来存储调度信息。当我重新启动 tomcat 时,quartz 已重新启动,但它不会重新运行作业。例如,我有一个工作要打印“aaa”10次,我运行了3次后重新启动了tomcat,剩下的7次就不会完成。下面是spring的配置文件,所有的作业和触发器都将由用户创建,因此只有一个bean。

<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init="false"></bean>

下面是quartz.properties。

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = false
# Configure Datasources
#============================================================================
org.quartz.jobStore.dataSource = myDS
org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://localhost:3306/quartz1x?useUnicode=true&characterEncoding=utf8
org.quartz.dataSource.myDS.user = root
org.quartz.dataSource.myDS.password =111111
org.quartz.dataSource.myDS.maxConnections = 10

Spring感染了Scheduler,下面是代码

        JobDetail jobDetail = new JobDetail("jName","gName", NewJob.class);
SimpleTrigger simpleTrigger = new SimpleTrigger("jName1","gName1");
simpleTrigger.setStartTime(new Date());
simpleTrigger.setRepeatInterval(3000);
simpleTrigger.setRepeatCount(10);

scheduler.scheduleJob(jobDetail, simpleTrigger);

NewJob.java

public class NewJob implements Job {

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println(new Date());
}

}

如果我不使用spring,而是使用servlet(org.quartz.ee.servlet.QuartzInitializerServlet),就没有问题。

最佳答案

Spring默认不读取quartz.properties,你应该像下面一样在bean中编写配置文件。

    <bean id="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init="false">
<property name="configLocation" value="classpath:quartz.properties" />
</bean>

关于java - 为什么 quartz 不重新启 Action 业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27813708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com