许多并发读取 + 一次写入导致 ObjectNotFound由于 ehcache 而导致的异常
我在高流量网站上使用Hibernate 3.6.8,ehcache 2.4.5(也尝试使用最新的2.8.0),jvm 1.6.0_22,有时我会遇到
ObjectNotFoundException:不存在具有给定标识符的行:[com.example.Foo#123]'
当通过最简单的代码创建新的(在本例中为 id 123)时:Foo
Foo foo = new Foo();
session.save(foo);
原因是在这个高流量网站的所有页面中,我都像这样:Foo
session.createQuery("from Foo").setCacheable(true).list();
存储 s 的表包含 1000 行,实体缓存在 ehcache 中:Foo
<class-cache class="com.example.Foo" usage="read-write" />
我的休眠配置的其他可能相关的部分是:
<property name="connection.url">jdbc:mysql://localhost:3306/example?characterEncoding=UTF-8</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">60</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.acquireRetryAttempts">1</property>
<property name="hibernate.c3p0.acquireRetryDelay">1</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.jdbc.use_scrollable_resultset">true</property>
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</property>
<property name="net.sf.ehcache.configurationResourceName">/ehcache.xml</property>
<property name="hibernate.cache.use_query_cache">true</property>
错误发生一次,然后消失。我怀疑ehcache查询缓存已使用新的实体ID(123)id更新,但实体缓存尚未使用该实体的内容进行更新。我使用JMeter在本地相当容易地重现了这一点。
关于如何解决这个问题的任何想法?
创建时,将抛出一次。另一方面,如果我删除了一个实例,那么我不断(并且永远)得到的每次执行。堆栈跟踪可以在 http://pastebin.com/raw.php?i=dp3HBgDBFoo
ObjectNotFoundException
Foo
ObjectNotFoundException
.list()