如何终止从jboss超时的数据库事务 [英] How to kill db transaction that timed out from jboss

查看:77
本文介绍了如何终止从jboss超时的数据库事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jboss 4.2.3

它具有设置"TransactionTimeout"(位于jboss-service.xml中),用于指定允许执行事务多长时间.

不幸的是,当超时过去时,执行不会立即中止,如果事务正在执行某项操作,则仅将其标记为稍后回滚.

效果是-例如,当我有一个长久的事务并且线程在prepareStatement.execute上消失时,当TransactionTimeout通过时,什么也没有发生,客户端仍然挂起,只有当prepareStatement完成时,才会发生事务被滚动的异常回来.

我从 http://management尝试了拦截器-platform.blogspot.com/2008/11/transaction-timeouts-and-ejb3jpa.html ,但是它仅将线程标记为中断,大多数方法在执行时都不会对此进行检查,因此效果是相同的. /p>

我也尝试设置了prepareStatement.setQueryTimeout,但是在Oracle(我们使用的)上,它会等待中止会话,直到oracle愿意这样做(例如,它不会中止正在执行 dbms_lock的plsql过程) .sleep (..)).

我想终止与事务相关联的数据库会话,该会话超时-我知道它与哪个事务以及与哪个线程相关联(因为我使用上面给出的链接中的拦截器),但是我不知道不知道如何获取事务绑定的会话-我必须获取它,然后杀死它-然后线程将被中断.

我错过了更简单的解决方案,还是做错了:)?

解决方案

仅对此主题进行了一些研究.有一个JTA配置参数InterruptThreads,默认为false.阅读文档,这意味着该线程将不会中断,而只会像您所说的那样标记为回滚.

类似选项的声音是: 1)将InterruptThreads(在jboss-service.xml中)设置为true和 2)还有一些有关定义自己的"CheckedAction"类的讨论,该类包含在事务处理和终止过程中.

与默认设置类似,基本上允许该线程到达某个位置,在该位置将回滚您的更新.

还有交易收割者配置,默认为2分钟-他们检查哪些交易可能超时-因此默认超时为5分钟,加上2分钟收割者-最坏的情况是假设您中断了线程,您可以等待7分钟.

I use jboss 4.2.3.

It has setting "TransactionTimeout" (in jboss-service.xml), that specifies how long Transaction is allowed to execute.

Unfortunately, when the timeout passes, the execution isn't aborted right now, if the transaction is doing something, only it is marked to be rolled back later.

The effect is - when I have long lasting transaction and thread is wainting on preparedStatement.execute for example, and when the TransactionTimeout passes, nothing happend, client still hang, only when the preparedStatement finishes, there is Exception that transaction was rolled back.

I tried the interceptor from http://management-platform.blogspot.com/2008/11/transaction-timeouts-and-ejb3jpa.html but it only markse thread as interrupted, most methods won't check for this when executing, so effect is the same.

I've tried also setting preparedStatement.setQueryTimeout, but on Oracle (which we use), it waits with aborting session till oracle feels like doing it (for example it won't abort plsql procedure that is doing dbms_lock.sleep(..)).

I would like to kill database session associated with the transaction, that timed out - I know which transaction it is, and with which thread it is associated (because I use the interceptor from the link I given above), but I don't know how to get session the transaction is bound to - I have to get it, to kill it - and then the thread will get interrupted.

Am I missing easier solution, or doing it completely wrong :) ?

解决方案

Just did some research on this topic. There is an JTA configuration parameter InterruptThreads, which defaults to false. Reading the docs, this means that the thread will NOT be interrupted but merely marked for rollback as you said.

Sounds like the options are: 1) set InterruptThreads (in jboss-service.xml) to true and 2) Also some discussion on defining your own 'CheckedAction' class, which is included in the transaction handling and termination process.

Looks like with the default settings, the thread is basically allowed to get to some point where it will rollback your update.

There's also the transaction reaper configuration, which default to 2 minutes - where they check on which transactions may have timeed out - so with the default timeout of 5 minutes, plus the 2 minute reaper - worst case, assuming you interrupt threads, you could wait 7 minutes.

这篇关于如何终止从jboss超时的数据库事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆