java 交易是交替超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4724544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transaction is alternating Timeouts
提问by rayman
I am using jboss 5.1.x, EJB3.0
我正在使用 jboss 5.1.x、EJB3.0
I have MDB which listens to JMS queue. when the MDB taking a message, it dispatch a msg via TCP to some modem. sometimes that Modem doesnt response when the server is waiting for an answer:
我有监听 JMS 队列的 MDB。当 MDB 接收一条消息时,它会通过 TCP 向某个调制解调器发送一条消息。有时,当服务器正在等待答案时,调制解调器没有响应:
byte[] byteData = receive(is);
coz I cant set timeout on InputStream.
因为我无法在 InputStream 上设置超时。
so thanks to the EJB container the transaction timeout(which is there by default) rolling back the operation and then a retry executed again.
因此,由于 EJB 容器,事务超时(默认情况下存在)回滚操作,然后再次执行重试。
this mechanism by default works fine for me, the problem is:
默认情况下,这种机制对我来说很好用,问题是:
Sometimes the transaction never timed out, and after long time I get the following msg in the console:
有时事务从未超时,很长时间后我在控制台中收到以下消息:
15:18:22,578 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_18] - TransactionReaper::check timeout for TX a6b2232:5f8:4d3591c6:76 in state RUN
15:18:22,578 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_58] - Abort of action id a6b2232:5f8:4d3591c6:76 invoked while multiple threads active within it.
15:18:22,578 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.CheckedAction_2] - CheckedAction::check - atomic action a6b2232:5f8:4d3591c6:76 aborting with 1 threads active!
15:18:22,578 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TransactionReaper_7] - TransactionReaper::doCancellations worker Thread[Thread-10,5,jboss] successfully canceled TX a6b2232:5f8:4d3591c6:76
Any idea what's wrong? and why sometimes it work and sometimes it doesnt?
知道出了什么问题吗?为什么有时它起作用有时不起作用?
thanks,
谢谢,
ray.
射线。
采纳答案by Nayan Wadekar
JBossAS that uses the Arjuna's Transaction Manager. In EJB3 interceptor chain would begin to unroll and eventually hit the transaction manager interceptors whose job it is to abort the transaction.
使用 Arjuna 的事务管理器的 JBossAS。在 EJB3 中,拦截器链将开始展开并最终击中事务管理器拦截器,其工作是中止事务。
For MDB's you can annote it with
@ActivationConfigProperty(propertyName="transactionTimeout" value="1500")
For other beans you can have
@TransactionTimeout(1500)
at class level or method level.
对于 MDB,你可以用
@ActivationConfigProperty(propertyName="transactionTimeout" value="1500")
对于其他 bean,您可以
@TransactionTimeout(1500)
在类级别或方法级别拥有。
When the transaction manager detects that the transaction has timed out and then aborts it from within an asynchronous thread (different from the thread running in method), but it never sends an interrupt to the currently running thread.
当事务管理器检测到事务已超时,然后从异步线程(与方法中运行的线程不同)中中止它,但它永远不会向当前运行的线程发送中断。
Therefore resulting in : invoked while multiple threads active within it... aborting with 1 threads active!
因此导致:在其中多个线程处于活动状态时调用...中止 1 个线程处于活动状态!
Edit :
编辑 :
//---
ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();
while (root.getParent() != null)
root = root.getParent();
findAllThread(root,0);
//---
public static findAllThread(ThreadGroup threadGroup, int level){
int actCount = threadGroup.activeCount();
Thread[] threads = new Thread[actCount*2];
actCount = threadGroup.enumerate(threads, false);
for (int i=0; i<actCount; i++) {
Thread thread = threads[i];
thread.interrupt();
}
int groupCount = threadGroup.activeGroupCount();
ThreadGroup[] groups = new ThreadGroup[numGroups*2];
groupCount = threadGroup.enumerate(groups, false);
for (int i=0; i<groupCount; i++)
findAllThread(groups[i], level+1);
//---
It will list other active threads also like Reference Handler, Finalizer, Signal Dispatcher etc.
它还会列出其他活动线程,如参考处理程序、终结器、信号调度程序等。