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

发布于 2024-09-11 05:06:07 字数 4638 浏览 11 评论 0原文

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

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

> 我的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.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

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

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

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

I'm using quartz 1.6.5. I recently moved from Quartz Job Store from RamJobStore to org.quartz.impl.jdbcjobstore.JobStoreTX. Since this, I've started to see ClassCastException in my log whenever quartz tries to run a job.

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


My quartz.properties looks like:

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


I initialize my scheduler using the following code:

org.quartz.Scheduler quartzScheduler = new StdSchedulerFactory("quartz.properties").getScheduler();

The same code works with a RAMJobStore but not with a JobStoreTX. What could I be missing here?
I enabled logging and this is what I find in the logs:

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

Update: I tried the same with org.quartz.impl.jdbcjobstore.JobStoreCMT and still the same issue persists.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

病毒体 2024-09-18 05:06:07

问题可能是您已经子类化了 JobDetail

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

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

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

The problem is likely to be that you have subclassed JobDetail.

When you used RAMJobStore, your ScheduledJobDetail objects would have been kept in memory, and so you could cast back from JobDetail without a problem. When using a database JobStore, though, Quartz will be reconstructing the JobDetail objects itself, and it has no way of knowing that you want it to use a custom class for this, and so you get the exception.

Even if Quartz did know to use a ScheduledJobDetail, it would have no way of handling the additional fields you added.

Subclassing JobDetail is not the way to go. You need to find some other way of encoding this information, without subclassing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文