<<上篇 | 首页 | 下篇>>

一个在Spring里使用quartz完成时序调度工作的例子

Spring提供了支持时序调度的整合类。现在, Spring支持内置于1.3版本以来的JDK中的Timer和Quartz Scheduler(http://www.quartzscheduler.org)。 两个时序调度器通过FactoryBean建立,保持着可选的对Timers或者Triggers的引用。更进一步的, 对于Quartz Scheduler和Timer两者存在一个方便的类允许你调用目标对象(类似于通常的MethodInvokingFactoryBeans)上的某个方法。

阅读全文……

标签 : , ,

Commons Logging自动发现日志工具过程和Log4j的初始化

Jakarta Commons Logging (JCL)提供了统一的日志接口,它目的是成为轻量级和不依赖其他日志工具的抽象层。它把一个简单的日志抽象提供给二次开发者,它允许用户插入一个指定的日志实现。
JCL为其他日志工具提供了一个代理日志实现,包括Log4JAvalon LogKit,JDK 1.4,以及JDK1.4日志API的实现。这个接口类似的映射到Log4j和LogKit。

下面是Commons Logging  (JCL)自动地发现选择一个日志实现工具的过程:

阅读全文……

标签 :

Hibernate optimistic locking exception

HibernateOptimisticLockingFailureException,The error occurs because at least 2 transactions are working on the same record(s). If a record is read by 2 transactions, and if the record is saved by one transaction first, and then by the second one, an optimistic locking exception is thrown in the second transaction, because the assumption that nobody else was going to modify the record, doesn't hold. (Optimistic locking = You are optimistic about the facts that nobody else is going to need the same record)

Are you using multithreading in batch mode? Probably multiple transactions are modifying the same record at the same moment.

There are different solutions:
1) make sure (by design) that records that are going to be updated, are touched by only a single transaction at any given moment
2) instead of optimistic locking, use pessimistic locking (problem: reduces scalability, and added complexity in application)
3) retry the transaction: make sure that no non-transactional state is kept between retries.

标签 : ,