Showing posts with label jbosstm. Show all posts
Showing posts with label jbosstm. Show all posts

Wednesday, March 16, 2011

Transaction Timeout in JBoss

as explained here (it doesn't go in too much detail though...)

in conf/jboss-service.xml you will find either:

mbean code="org.jboss.tm.TransactionManagerService"
attribute name="TransactionTimeout" 300


or
mbean code="com.arjuna.ats.jbossatx.jta.TransactionManagerService"
attribute name="TransactionTimeout" 300

(JBoss can be configured with either TM)

otherwise you can annotate your EJB method with

org.jboss.annotation.ejb.TransactionTimeout
(value is in SECONDS I suppose)

but apparently this annotation works only with the jboss TM

http://community.jboss.org/thread/147020


Here the also complain about this.


Anyway you can still grab the transaction and set timeout in your code...ONLY IF YOU DO BMT!

don't use EntityManager.getTransaction(), this is a EntityTransaction and will not expose you the UserTransaction timeout...

you have the SessionContext (=EJBContext) injected this way:

@Resource
private SessionContext sctx;
...

sctx.getUserTransaction().setTransactionTimeout(1500);


if you do this on a CMT, you get this:

java.lang.IllegalStateException: Container bla: it is illegal to inject UserTransaction into a CMT bean
at org.jboss.ejb3.BaseSessionContext.getUserTransaction(BaseSessionContext.java:248)






/:o{=