【发布时间】:2012-01-19 23:38:00
【问题描述】:
我正在使用:JBoss AS 4.2.3、JBoss Cache 1.4.1 SP12、Hibernate 3.2.6; JPA 1.0.1 与
<attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
<attribute name="IsolationLevel">READ_COMMITTED</attribute>
和
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_structured_entries" value="true"/>
<property name="hibernate.cache.usage" value="transactional"/>
<property name="hibernate.cache.provider_class"
value="org.hibernate.cache.TreeCacheProvider"/>
<property name="hibernate.treecache.local_puts_only" value="true"/>
<property name="hibernate.treecache.querycache.local_writes_only" value="true"/>
设置;
我有这样的实体:
@Entity
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region = "AccountCache")
public class Account {
...some fields and methods...
}
和
@Entity
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class User {
....
@ManyToOne
private Account account;
....
}
所以,我有计时器服务,它获取有关 Account 的信息并做一些事情(不更改 Account,只是获取并更改另一个实体)。当用户登录并在页面中工作时(切换页面,在其中做一些事情(不更改Account 或User 实体)),此时计时器服务开始工作,用户页面被阻止,并在 15 秒后抛出错误:
....many lines of stack and such errors...
Error performing load command
org.hibernate.cache.CacheException: org.jboss.cache.lock.TimeoutException:
failure acquiring lock: fqn=/default/AccountCache,
caller=Thread[http-192.0.2.58-80-6,5,jboss], lock=write
owner=GlobalTransaction:<null>:88 (org.jboss.cache.lock.LockStrategyReadCommitted@63b596)
....many lines of stack and such errors...
看来GlobalTransaction:<null>:88是用户tx,caller是timer service。
通常用户线程工作正常,不到 15 秒。如果在Account 中禁用@Cache 一切正常(似乎)。
如果启用Optimistic锁方案,在同一并发下(有时)会抛出这样的错误:
Caused by: org.jboss.cache.optimistic.DataVersioningException:
Tx attempted to create /default/AccountCache/com.****.entity.account.Account#1 anew.
It has already been created since this tx started by another (possibly remote) tx.
还有问题)))
有什么问题?是TreeCache 问题,还是我的应用程序问题?
我做错了什么?由容器管理的所有事务...
【问题讨论】:
-
您是否使用了galder.zamarreno.com/?p=56 中建议的缓存提供程序,该提供程序后来在galder.zamarreno.com/?p=227 中进行了更新?有关更多信息,请参阅community.jboss.org/wiki/…。此缓存提供程序旨在避免锁定问题。
标签: hibernate jakarta-ee concurrency deadlock second-level-cache