首页 新闻 会员 周边 捐助

quartz2.1.7 启动后TRIGGER_STATE直接就变为ERROR

0
悬赏园豆:50 [已关闭问题] 关闭于 2013-04-23 15:13

想用quartz做一个定时任务,定时任务都持久化到mysql数据库, 
每次添加任务以后,数据库里面有数据,但任务没有执行(我设置的是马上执行),TRIGGER_STATE就变为ERROR.

1 <bean id="scheduler" lazy-init="false"  
2         class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
3         <property name="dataSource">  
4             <ref bean="scheduleDataSource" />  
5         </property>  
6         <property name="autoStartup" value="true" />  
7         <property name="schedulerFactoryClass" value="org.quartz.impl.StdSchedulerFactory"></property>  
8         <property name="configLocation" value="classpath:quartz.properties" />  
9         <property name="schedulerName" value="cronScheduler" /> 
 1 org.quartz.scheduler.instanceName = EvanLilyScheduler 
 2 org.quartz.scheduler.instanceId = AUTO 
 3 
 4 #============================================================================
 5 # Configure ThreadPool  
 6 #============================================================================
 7 
 8 org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool 
 9 org.quartz.threadPool.threadCount = 25 
10 org.quartz.threadPool.threadPriority = 5 
11 
12 #============================================================================
13 # Configure JobStore  
14 #============================================================================
15 
16 org.quartz.jobStore.misfireThreshold = 60000 
17 org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX 
18 
19 # 不同数据库系统中某一特定方言的驱动代理mysql 
20 org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate 
21 
22 org.quartz.jobStore.useProperties=false 
23 org.quartz.jobStore.dataSource=DS 
24 #是否集群 
25 org.quartz.jobStore.isClustered=false 
26 
27 #============================================================================
28 # Configure Datasources 
29 #============================================================================
30 #mysql 
31 org.quartz.dataSource.DS.driver = com.mysql.jdbc.Driver 
32 org.quartz.dataSource.DS.URL = jdbc:mysql://localhost:3306/schedul 
33 org.quartz.dataSource.DS.user = root 
34 org.quartz.dataSource.DS.password = 
35 
36 org.quartz.dataSource.DS.maxConnections = 5 
37 org.quartz.scheduler.classLoadHelper.class=org.quartz.simpl.CascadingClassLoadHelper
 1 JobDetail jobDetail = newJob(HttpJobExecutor.class) 
 2                     .withIdentity(httpJob.getJobName(), HttpJobDO.JOB_GROUP) 
 3                     .withDescription(httpJob.getDescription()) 
 4                     .storeDurably(true)//没有trigger关联时自动删除 
 5                     .requestRecovery()//失败后重做 
 6                     .build(); 
 7 TriggerBuilder<Trigger> triggerBuilder = newTrigger() 
 8                     .withIdentity(httpJob.getJobName()) 
 9                     .endAt(httpJob.getEndTime()); 
10 triggerBuilder.startNow(); 
11 CronScheduleBuilder cronScheduleBuilder = cronSchedule(httpJob.getCronExpression()); 
12                 triggerBuilder.withSchedule(cronScheduleBuilder); 
13 Trigger trigger = triggerBuilder.build(); 
14 
15             scheduler.scheduleJob(jobDetail, trigger); 

谢谢

Evanlee的主页 Evanlee | 初学一级 | 园豆:65
提问于:2013-04-17 13:50
< >
分享
所有回答(3)
0

我表示没看懂,等待高手····

不负春光,努力生长 | 园豆:1382 (小虾三级) | 2013-04-17 16:40
0

马上执行的直接用 SimpleTrigger吧

  IJobDetail job = JobBuilder.Create<SampleJob>()
      .WithIdentity("remotelyAddedJob", "default")
      .Build();
 //job 参数
  JobDataMap map = job.JobDataMap;
  map.Put("msg", "Your remotely added job has executed!");

  ITrigger trigger = TriggerBuilder.Create()
      .WithIdentity("remotelyAddedTrigger", "default")
      .ForJob(job.Key)
      .StartNow()      //立即执行
      .Build();

还有 可以添加 trigger listener 添加trigger出错的话把错误记录下来 容易debug

gunsmoke | 园豆:3592 (老鸟四级) | 2013-04-19 12:37
0

是版本问题,2.1.7有问题,改了版本问题解决

Evanlee | 园豆:65 (初学一级) | 2013-04-23 15:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册