`
eyejava
  • 浏览: 1268674 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

怒了,spring对quartz的集成偏与我作对...

阅读更多
按spring的文档写了个最简单的quatz应用,竟然一直报错说:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean' defined in class path resource [applicationContext-rules.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Table 'cs.qrtz_locks' doesn't exist [See nested exception: java.sql.SQLException: Table 'cs.qrtz_locks' doesn't exist]]
查论坛得到如下信息:
dwangel 写道
另外可能是自动装配惹得祸,存在dataSource这个bean就自动用数据库的状态维持了。

dwangel 写道
foxty 写道
因为这个时候你的quartz是jobstore用的HDBCJobStore模式,此时会从数据库查询任务。

你如果只是测试的话,可以在你的classpath下加一个文件quartz.properties,并且加上一句org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore 。就会采取内存存储的模式了。

或者可以直接在spring配置中做:

<bean name="quartzScheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.jobStore.class">
org.quartz.simpl.RAMJobStore
</prop>
</props>
</property>
</bean>

autowire真是一个万恶的家伙,出了错让你完全不知道怎么回事. 这个问题整了我一个下午,怒了.
设置org.quartz.jobStore.class为org.quartz.simpl.RAMJobStore也是没有用的.
因为
if (this.dataSource != null) {
				mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
			}

SchedulerFactoryBean的setDataSource(DataSource)方法javadoc说:
Set the default DataSource to be used by the Scheduler. If set, this will override corresponding settings in Quartz properties.

Note: If this is set, the Quartz settings should not define a job store "dataSource" to avoid meaningless double configuration.

A Spring-specific subclass of Quartz' JobStoreCMT will be used. It is therefore strongly recommended to perform all operations on the Scheduler within Spring-managed (or plain JTA) transactions. Else, database locking will not properly work and might even break (e.g. if trying to obtain a lock on Oracle without a transaction).

Supports both transactional and non-transactional DataSource access. With a non-XA DataSource and local Spring transactions, a single DataSource argument is sufficient. In case of an XA DataSource and global JTA transactions, SchedulerFactoryBean's "nonTransactionalDataSource" property should be set, passing in a non-XA DataSource that will not participate in global transactions.

See Also:
setNonTransactionalDataSource
setQuartzProperties
setTransactionManager
LocalDataSourceJobStore
分享到:
评论
2 楼 eyejava 2007-03-24  
IntrospectorCleanupListener javadoc:
引用
If the JavaBeans Introspector has been used to analyze application classes, the system-level Introspector cache will hold a hard reference to those classes. Consequently, those classes and the web application class loader will not be garbage-collected on web app shutdown! This listener performs proper cleanup, to allow for garbage collection to take effect.
Unfortunately, the only way to clean up the Introspector is to flush the entire cache, as there is no way to specifically determine the application's classes referenced there. This will remove cached introspection results for all other applications in the server too.
...
Application classes hardly ever need to use the JavaBeans Introspector directly, so are normally not the cause of Introspector resource leaks. Rather, many libraries and frameworks do not clean up the Introspector: e.g. Struts and Quartz.


这个Introspector.flushCaches()只是迫不得已的方法,而且是为gc没做好的事情做善后工作。


1 楼 bitlong 2007-03-24  
我有一点不明白:
public class IntrospectorCleanupListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent event) {
}

public void contextDestroyed(ServletContextEvent event) {
Introspector.flushCaches();
}

}

这个Lisnter实在WebappDestory的时候,contextDestroyed才有实现。
WebApp一直在运行,不会执行Introspector.flushCaches(); 阿

相关推荐

    Autofac.Extras.Quartz, Quartz.Net的Autofac集成.zip

    Autofac.Extras.Quartz, Quartz.Net的Autofac集成 Autofac.Extras.Quartz用于 Quartz.Net的Autofac集成包。Autofac.Extras.Quartz 为每个石英作业创建嵌套的litefime作用域。 完成作业执行后释放嵌套作用域。这允许...

    关于spring中quartz的配置

    &lt;bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt; &lt;!-- 配置Quartz属性 --&gt; &lt;property name="configLocation" value="classpath:quartz.properties"/&gt; &lt;!...

    spring集成quartz集群配置

    Spring提供了`org.springframework.scheduling.quartz.JobDetailBean`来创建Job,`org.springframework.scheduling.quartz.CronTriggerBean`或`SimpleTriggerBean`来定义触发规则。在Spring配置文件中,我们可以声明...

    spring+quartz demo

    Spring 提供了与 Quartz 集成的模块,使得在 Spring 应用程序中使用 Quartz 更加便捷,包括 Job 实例的管理、触发器的配置以及对 Quartz Scheduler 的控制。 在这个 "spring+quartz demo" 中,我们可以学习到如何将...

    Java_Spring与Quartz的整合

    - 通过实现`org.springframework.scheduling.quartz.JobExecutionException`,可以捕获Job执行过程中的异常,进行统一处理。 8. **事务支持** - 如果Job需要在数据库事务中执行,可以利用Spring的事务管理功能,...

    spring集成quartz所需文件

    标题 "spring集成quartz所需文件" 指的是将 Spring 框架与 Quartz 进行整合,以利用 Quartz 的定时任务功能。这种集成使得开发者可以在 Spring 环境下方便地管理调度任务,实现灵活的定时任务逻辑。 在描述中提到 ...

    Spring+quartz相关jar包.rar

    例如,Spring 提供了 `org.springframework.scheduling.quartz` 包,该包包含了一些用于配置 Quartz 的工具类和Bean定义。开发者可以通过 Spring 的 XML 配置或者注解方式来定义 Quartz 作业和触发器,使得任务调度...

    quartz和spring-quartz

    而Spring-Quartz则是Spring框架对Quartz的集成,它使得在Spring应用中使用Quartz变得更加方便。 Quartz的核心概念包括Job(作业)、Trigger(触发器)和Calendar(日历)。Job是实际要执行的任务,Trigger定义了Job...

    spring和quartz整合示例

    所需jar如下: spring-beans-3.2.4.RELEASE.jar spring-core-3.2.4.RELEASE.jar spring-expression-3.2.4.RELEASE....quartz-all-2.1.7.jar spring-tx-3.2.4.RELEASE.jar slf4j-log4j12-1.6.1.jar slf4j-api-1.6.1.jar

    spring2与quartz在Web整合

    在将 Spring 2 与 Quartz 整合到 Web 应用中时,主要涉及以下几个关键知识点: 1. **Spring 2 的核心概念**:Spring 2 提供了 IoC(Inversion of Control,控制反转)和 AOP(Aspect-Oriented Programming,面向切...

    spring boot集成quartz定时器

    import org.springframework.scheduling.quartz.CronTriggerFactoryBean; import org.springframework.scheduling.quartz.SchedulerFactoryBean; @Configuration public class QuartzConfig { @Bean public ...

    Spring4.X+Quartz2.X

    3. **定义Job**:创建实现`org.springframework.core.task.TaskExecutor`接口的类,或者直接使用`org.springframework.scheduling.quartz.JobDetailBean`,来定义具体的任务逻辑。 4. **配置Trigger**:创建一个...

    Spring集成Quartz调度框架.pdf

    #### 四、Spring与Quartz的集成 Spring框架提供了与Quartz无缝集成的支持,使得开发者能够在Spring环境中方便地管理和使用Quartz的功能。通过Spring的依赖注入特性,可以简化Quartz的配置过程,提高代码的可维护性...

    Spring集成Quartz定时任务框架介绍.docx

    &lt;bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt; ``` - **配置触发器**: ```xml &lt;bean id="cronTrigger" class="org.springframework....

    spring+quartz使用jar包

    1. **Spring与Quartz的整合**:Spring 提供了对Quartz的集成支持,通过`org.springframework.scheduling.quartz`包中的类,如`SchedulerFactoryBean`和`ThreadPoolTaskExecutor`,可以轻松地将Quartz纳入Spring的...

    spring 集成quartz 用数据库实现quartz的集群

    &lt;bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt; &lt;property name="configLocation" value="classpath:quartz.properties"/&gt; ``` 在`quartz....

    spring-quartz定时设置详细说明

    quartz.jobStore.type=org.quartz.impl.jdbcjobstore.StdJDBCJobStore quartz.jobStore.dataSource=myDS quartz.dataSource.myDS.driverClass=com.mysql.jdbc.Driver quartz.dataSource.myDS.URL=jdbc:mysql://...

    spring3.0 + Quartz1.52 + applicationContext.xml

    &lt;bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt; &lt;property name="configLocation" value="classpath:quartz.properties"/&gt; &lt;!-- 其他属性配置 --&gt; ``` `...

    spring3-quartz1.x

    &lt;bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt; &lt;!-- Quartz properties --&gt; &lt;bean id="myJob" class="org.springframework.scheduling.quartz....

    spring-boot-quartz

    import org.springframework.scheduling.quartz.SchedulerFactoryBean; @Configuration public class QuartzConfig { @Autowired private SchedulerFactoryBean schedulerFactoryBean; public void init() { ...

Global site tag (gtag.js) - Google Analytics