gpt4 book ai didi

java - quartz - java.lang.ClassCastException org.quartz.JobDetail 无法使用 JobStoreTX 转换为 ScheduledJobDetail

转载 作者:行者123 更新时间:2023-12-01 05:54:54 28 4
gpt4 key购买 nike

我正在使用 quartz 1.6.5。我最近从 Quartz Job Store 从 RamJobStore 迁移到 org.quartz.impl.jdbcjobstore.JobStoreTX。从那时起,每当quartz尝试运行作业时,我就开始在日志中看到ClassCastException



<pre>Jul 26, 2010 3:10:00 AM org.quartz.core.ErrorLogger schedulerError
SEVERE: Job (group52.52 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.ClassCastException: org.quartz.JobDetail cannot be cast to ScheduledJobDetail]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: java.lang.ClassCastException: org.quartz.JobDetail cannot be cast to ScheduledJobDetail
at ScheduledJob.execute(ScheduledJob.java:150)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 more
</pre>

我的quartz.properties 看起来像:



<pre>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.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.dataSource = myDS
org.quartz.dataSource.dsjta.jndiURL=myDs
org.quartz.jobStore.useProperties=true
</pre>

我使用以下代码初始化调度程序:
org.quartz.Scheduler quartzScheduler = new StdSchedulerFactory("quartz.properties").getScheduler();
相同的代码适用于 RAMJobStore,但不适用于 JobStoreTX。我在这里可能会缺少什么?我启用了日志记录,这是我在日志中找到的内容:



<pre>136672 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore - Lock 'TRIGGER_ACCESS' is desired by: DefaultQuartzScheduler_QuartzSchedulerThread
136672 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore - Lock 'TRIGGER_ACCESS' is being obtained: DefaultQuartzScheduler_QuartzSchedulerThread
136672 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore - Lock 'TRIGGER_ACCESS' given to: DefaultQuartzScheduler_QuartzSchedulerThread
136703 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore - Lock 'TRIGGER_ACCESS' retuned by: DefaultQuartzScheduler_QuartzSchedulerThread
136703 [DefaultQuartzScheduler_QuartzSchedulerThread] DEBUG org.quartz.simpl.SimpleJobFactory - Producing instance of Job 'group152.152', class=ScheduledJob
136703 [DefaultQuartzScheduler_Worker-3] DEBUG org.quartz.core.JobRunShell - Calling execute on job group152.152
136703 [DefaultQuartzScheduler_Worker-3] ERROR org.quartz.core.JobRunShell - Job group152.152 threw an unhandled Exception:
java.lang.ClassCastException: org.quartz.JobDetail cannot be cast to ScheduledJobDetail
at ScheduledJob.execute(SchedulerQuartzImpl.java:150)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
136703 [DefaultQuartzScheduler_Worker-3] ERROR org.quartz.core.ErrorLogger - Job (group152.152 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.ClassCastException: org.quartz.JobDetail cannot be cast to ScheduledJobDetail]
at org.quartz.core.JobRunShell.run(JobRunShell.java:227)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.ClassCastException: org.quartz.JobDetail cannot be cast to ScheduledJobDetail
at ScheduledJob.execute(SchedulerQuartzImpl.java:150)
at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
... 1 more
136703 [DefaultQuartzScheduler_Worker-3] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore - Lock 'TRIGGER_ACCESS' is desired by: DefaultQuartzScheduler_Worker-3
136703 [DefaultQuartzScheduler_Worker-3] DEBUG org.quartz.impl.jdbcjobstore.SimpleSemaphore - Lock 'TRIGGER_ACCESS' is being obtained: DefaultQuartzScheduler_Worker-3
</pre>

更新:我对 org.quartz.impl.jdbcjobstore.JobStoreCMT 进行了相同的尝试,但仍然存在相同的问题。

最佳答案

问题可能是您对 JobDetail 进行了子类化。

当您使用 RAMJobStore 时,您的 ScheduledJobDetail 对象将保存在内存中,因此您可以毫无问题地从 JobDetail 进行强制转换。但是,当使用数据库JobStore时,Quartz将重建JobDetail对象本身,并且它无法知道您希望它为此使用自定义类,所以你得到了异常(exception)。

即使 Quartz 确实知道使用 ScheduledJobDetail,它也无法处理您添加的其他字段。

子类化JobDetail并不是正确的方法。您需要找到一些其他方式来编码此信息,而不需要子类化。

关于java - quartz - java.lang.ClassCastException org.quartz.JobDetail 无法使用 JobStoreTX 转换为 ScheduledJobDetail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3341125/

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