我对JPA相对较新,并且继承了#34;这段代码,但我有一个似乎是死锁/挂起的问题。只有当我们的数据库在一定时间内(维护)不可用时才会发生这种情况。可能有10个单独的线程/处理器,基本上有一个点击数据库异常,它会循环并尝试从中恢复,其他线程似乎挂起数天
我已经搜索了但如果这是重复,我无法找到我正在寻找的东西。
isCommunicationFailure()报告数据库错误并重新启动进程
主题#1 内部异常:java.sql.SQLException:Io异常:断开的pipeError代码:17002 at com.SomeClass.isCommunicationFailure
主题#2 信息:坚持...... 2015年2月14日下午7:55:23 com.SomeClass.transitionUncachedToState 信息:即将提交工作状态.... 2015年2月15日下午2:04:35 com.SomeClass.JPAJobStore< --- 这是我们重新启动流程的地方,因为它没有移动。
我需要设置某些OPTIMISTIC对象吗?锁定会超时吗?还是有其他一些基本的处理方法吗?
我正在使用Oracle DB后端。下面的persistence.xml(我已经手动更改了这个问题的一些类名是通用的)。
提前致谢...:)
public boolean transitionUncachedToState(Job job, String zId)
throws RAAException
{
boolean result = false;
String jobReqId = job.getJobRequestId();
Query query;
Job jpaJob;
long starttime, stoptime;
starttime = DateUtil.getCurrentUtcTime();
try {
query = em.createNamedQuery("getUnzippedJobUsingJobReqId");
query.setHint("javax.persistence.query.timeout", 30000);
query.setParameter("jobReqId", jobReqId);
jpaJob = (Job)query.getSingleResult();
em.refresh(jpaJob);
stoptime = DateUtil.getCurrentUtcTime();
logger.info("get jpaJob="+jpaJob.toString().substring(0, 512)
+ ", time in miliseconds " + (stoptime-starttime));
starttime = stoptime;
}
catch(NoResultException ex)
{
logger.info("job " + jobReqId + " can not be locked.");
return result;
}
//jpaReportCacheState = jpaJob.getJobDetails().getReportCacheState();
JobDetails jpaJobDetails = jpaJob.getJobDetails();
em.refresh(jpaJobDetails);
ProcessingState jpaState = jpaJobDetails.getProcessingState();
em.refresh(jpaState);
logger.info("Job.Z_STATE_UNPROCESSED="
+ Job.Z_STATE_UNPROCESSED
+ ", jpaState.getState()="+jpaState.getState());
if(Job.Z_STATE_UNPROCESSED.equals(jpaState.getState()))
{
// Set Job's report cache state to CACHING
job.setStartTime(DateUtil.getCurrentUtcTime());
job.setState(Job.Z_STATE_ZIPPING);
job.setId(zId);
job.setProcessingAttempts(job.getProcessingAttempts() + 1);
try {
logger.info(job.getId());
em.getTransaction().begin();
jpaState.setState(job.getState());
jpaState.setStartProcessingTime(new Date(job.getStartTime()));
jpaJob.setId(job.getId());
logger.info("Persisting...");
em.persist(jpaState);
em.persist(jpaJob);
logger.info("About to commit job state....");
em.getTransaction().commit();
em.clear();
stoptime = DateUtil.getCurrentUtcTime();
logger.info("Successful lock on job " + jobReqId
+ ", JPA update time in miliseconds " + (stoptime-starttime));
result = true;
}
catch(Exception ex) {
if(isCommunicationFailure(ex)) {
result = transitionUncachedToState(job, zId);
}
}
}
return result;
}
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd"
version="1.0">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>
oracle.toplink.essentials.PersistenceProvider
</provider>
<class>com.SomeClass.Job</class>
<properties>
<property name ="toplink.target-database" value="Oracle"/>
<property name="user" value="somthing"/>
<property name="password" value="somthing123"/>
<property name="toplink.logging.level" value="SEVERE"/>
<property name="toplink.logging.exceptions" value="true"/>
<!--<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>-->
<property name="toplink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="toplink.jdbc.url" value="jdbc:oracle:thin:@someurl"/>
<property name="toplink.jdbc.user" value="user"/>
<property name="toplink.jdbc.password" value="pass"/>
<property name="toplink.jdbc.bind-parameters" value="true"/>
<property name="toplink.cache.size.default" value="5000"/>
<property name="toplink.cache.shared.ContainerEntry" value="false"/>
<property name="toplink.cache.shared.Hosts" value="false"/>
<property name="toplink.cache.shared.default" value="true"/>
<property name="toplink.weaving" value="true"/>
<property name="toplink.jdbc.read-connections.max" value="1"/>
<property name="toplink.jdbc.read-connections.min" value="1"/>
<property name="toplink.jdbc.write-connections.max" value="1"/>
<property name="toplink.jdbc.write-connections.min" value="1"/>
<property name="toplink.cache.type.Order" value="Weak"/>
</properties>
</persistence-unit>