2

我在执行大量查询时遇到问题。

我需要在单个事务中执行超过 10,000 个本机 sql 查询。这些查询是动态生成的并缓存在系统中。查询生成完成后,这些查询将在单个事务中一一发送并执行。该应用程序使用 EJB 3 开发并在 JBoss 5.1 上运行。

如果查询数少于 7200(近似值),则应用程序可以正常工作。但是,如果查询数量超过此数量,则该方法会抛出 EJB 异常,并且事务会回滚。没有数据被持久化。

这是发生回滚的地方。[仅当查询数超过 7200 时]

 @TransactionAttribute(TransactionAttributeType.REQUIRED)
 public void confirmOrder(String[] queries) {
    for (int i = 0; i < queries.length; i++) {
        em.createNativeQuery(queries[i]).executeUpdate();        //line # 108
    }
    BigInteger bigInt = (BigInteger)em.createNativeQuery("select max(id) from order_item").getSingleResult();
    return bigInt!=null ? Long.valueOf(bigInt.longValue()) : null;
}

有没有办法增加可以在事务中执行的查询数量?请就此提出您的建议。

/维拉吉

The following is the error trace.

17:36:33,233 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3a3 in state  RUN
17:36:33,238 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_7] - TransactionReaper::doCancellations worker Thread[Thread-10,5,jboss] successfully canceled TX -3f57767b:bc55:4fd9d129:e3a3
17:36:33,635 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3bf in state  RUN
17:36:33,636 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_58] - Abort of action id -3f57767b:bc55:4fd9d129:e3bf invoked while multiple threads active within it.
17:36:33,636 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.CheckedAction_2] - CheckedAction::check - atomic action -3f57767b:bc55:4fd9d129:e3bf aborting with 1 threads active!
17:36:34,135 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3bf in state  CANCEL
17:36:34,635 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX -3f57767b:bc55:4fd9d129:e3bf in state  CANCEL_INTERRUPTED
17:36:34,636 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_6] - TransactionReaper::check worker Thread[Thread-10,5,jboss] not responding to interrupt when cancelling TX -3f57767b:bc55:4fd9d129:e3bf -- worker marked as zombie and TX scheduled for mark-as-rollback
17:36:34,636 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_11] - TransactionReaper::check failed to mark TX -3f57767b:bc55:4fd9d129:e3bf  as rollback only
17:36:34,904 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@5a720719
17:36:34,926 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_13] - TransactionReaper::doCancellations worker Thread[Thread-10,5,jboss] missed interrupt when cancelling TX -3f57767b:bc55:4fd9d129:e3bf -- exiting as zombie (zombie count decremented to 0)   ........   
  ......

17:36:34,935 ERROR [CardOrderCreateFacadeBean] Confirming order is failed.   
javax.ejb.EJBTransactionRolledbackException: Executing an update/delete query
    at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.security.RunAsSecurityInterceptorv2.invoke(RunAsSecurityInterceptorv2.java:94)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
    ........................
    ...............

Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
    at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:48)
    at rk.ejb.eao.OrderEAOImpl.confirmOrder(OrderEAOImpl.java:108)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
    at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76)
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62)
    at sun.reflect.GeneratedMethodAccessor358.invoke(Unknown Source)
    ........
    .......
4

2 回答 2

7

您可以根据需要在全局或方法级别增加事务超时。

  • 如果您想在方法级别执行此操作,可以使用以下注释。(超时设置为 1500 秒)@TransactionTimeout(1500)
  • 如果要全局执行此操作,则必须编辑位于 [server-instance]/deploy 目录中的 transaction-jboss-beans.xml 并更改超时参数值。例如:超时值为 1200 秒

    <property name="transactionTimeout">1200</property>

欲了解更多信息:https ://community.jboss.org/wiki/TransactionTimeout

于 2012-12-13T07:07:05.740 回答
5

我能够解决这个问题。尽管它显示了这样的异常,但这是由于事务回滚而发生的。回滚事务的确切原因是事务超时。当有大量查询要执行时,事务超时,最终结果就是上述异常。在 JBoss 事务配置中进行更改,消除了错误。

于 2012-06-20T12:35:28.357 回答