gpt4 book ai didi

java - Eclipselink 抛出 ConcurrentModificationException

转载 作者:行者123 更新时间:2023-12-02 06:50:18 27 4
gpt4 key购买 nike

我在应用程序代码中遇到一些 ConcurrentModificationException 问题:

   Caused by: Exception [EclipseLink-2004] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.ConcurrencyException
Exception Description: A signal was attempted before wait() on ConcurrencyManager. This normally means that an attempt was made to
commit or rollback a transaction before it was started, or to rollback a transaction twice.
at org.eclipse.persistence.exceptions.ConcurrencyException.signalAttemptedBeforeWait(ConcurrencyException.java:84)
at org.eclipse.persistence.internal.helper.ConcurrencyManager.releaseReadLock(ConcurrencyManager.java:489)
at org.eclipse.persistence.internal.identitymaps.CacheKey.releaseReadLock(CacheKey.java:392)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.cloneAndRegisterObject(UnitOfWorkImpl.java:1022)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.cloneAndRegisterObject(UnitOfWorkImpl.java:933)
at org.eclipse.persistence.internal.sessions.UnitOfWorkIdentityMapAccessor.getAndCloneCacheKeyFromParent(UnitOfWorkIdentityMapAccessor.java:197)
at org.eclipse.persistence.internal.sessions.UnitOfWorkIdentityMapAccessor.getFromIdentityMap(UnitOfWorkIdentityMapAccessor.java:125)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerExistingObject(UnitOfWorkImpl.java:3920)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerExistingObject(UnitOfWorkImpl.java:3874)
at org.eclipse.persistence.mappings.ObjectReferenceMapping.buildUnitofWorkCloneForPartObject(ObjectReferenceMapping.java:109)
at org.eclipse.persistence.mappings.ObjectReferenceMapping.buildCloneForPartObject(ObjectReferenceMapping.java:71)
at org.eclipse.persistence.internal.indirection.UnitOfWorkQueryValueHolder.buildCloneFor(UnitOfWorkQueryValueHolder.java:56)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:161)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:222)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:88)

分析代码,我找到了负责提供 EntityManager 的类:

import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import weblogic.javaee.CallByReference;

@Stateful (name = "DAOFactoryRemoteBean", mappedName = "DAOFactoryRemoteBean")
@CallByReference
public class DAOFactoryRemoteImplBean implements DAOFactoryRemoteBean {

@PersistenceContext(unitName = "server_unit")
private EntityManager em;

private static String getDAOName(Class<?> classeEntidade) {
String result = classeEntidade.getName()
.replace("org.networkmap.server.bean.",
"org.networkmap.server.bean.dao.");
result = result.concat("DAO");
return result;
}

@Override
public Object getDAO(Class<?> entityClass) {
NetworkmapDao result = null;

try {
result = (NetworkmapDao) Class.forName(getDAOName(entityClass))
.newInstance();
result.setEntityManager(em);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}

有很多 EJB 调用 getDAO 方法。以及该应用程序的大量用户。我想这确实可能会导致并发问题。

我对此没有很好的专业知识,但根据互联网上的一些搜索,考虑到 EntityManger 不是线程安全的,该代码似乎没有好的实践。我被这个问题困扰了:(

该应用程序使用 EclipseLink v2.4.2 API,在 Solaris 操作系统上的 Weblogic 10.3.5 上运行。而且 persistence.xml 上只声明了一个持久单元。

请有人帮助我。

最佳答案

您是否在不同线程中使用相同的EntityManager?如果是这样,请不要这样做。

否则,请包含完整的异常堆栈跟踪。

“result.setEntityManager(em);”是什么意思做什么?

关于java - Eclipselink 抛出 ConcurrentModificationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18114033/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com