我正在处理大量数据的性能问题。我正在尝试使用 weblogic 提供的工作管理器将工作分配到多个线程中。然而,我在尝试从表中获取特定记录时收到以下异常.
Caused by: java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:365)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:384)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:383)
at org.hibernate.util.IdentityMap.entryArray(IdentityMap.java:228)
at org.hibernate.util.IdentityMap.concurrentEntries(IdentityMap.java:89)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:890)
这是因为多线程吗?我使用的休眠版本是 3.6.1。异常是非常随机的:有时它可以完美运行,有时在 Eclipse 中放置一个调试点就可以了。
*编辑:引发异常的代码片段:
public Dto findRecentRequests()
{
Dto dto = getHibernateTemplate().executeFind(new HibernateCallback()
{
public Object doInHibernate(Session session) throws HibernateException
{
Query q = session.createQuery(newQuery);
q.setMaxResults(1);
return (Dto) query.uniqueResult();
}
});
return dto;
}