UserTransaction commit - can't close the Connection

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

UserTransaction commit - can't close the Connection

Vijay Pandey
Hi,

We are using BTM 1.3.2 and in some cases we get weird error, here is the flow of code

a) BTM Configuratiion and Datasource get initialized

b) We get the UserTransaction TransactionManagerServices.getTransactionManager();

c) Do some business processing and then we do flush on the Hibernate (3.1.3) current session

d) If no exception we do "commit" else rollback on UserTransaction

e) Sometimes when we are calling the close() on the Connection which is retrived from the datasource we get this error

java.sql.SQLException: error requeueing a JdbcPooledConnection from datasource AccessMSDatabaseDB2 in state ACCESSIBLE wrapping com.ibm.db2.jcc.DB2XAConnection@ce4bf7
        at bitronix.tm.resource.jdbc.JdbcPooledConnection.release(JdbcPooledConnection.java:148)
        at bitronix.tm.resource.jdbc.JdbcConnectionHandle.close(JdbcConnectionHandle.java:77)
        at gov.ms.mdes.access.server.framework.datasource.CustomBTMDataSource.closeConnection(CustomBTMDataSource.java:98)
        at gov.ms.mdes.access.server.framework.service.RMIService.executeTxn(RMIService.java:57)
        at sun.reflect.GeneratedMethodAccessor162.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
        at sun.rmi.transport.Transport$1.run(Transport.java:153)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
        at java.lang.Thread.run(Thread.java:595)
Caused by: bitronix.tm.internal.BitronixSystemException: cannot close a resource when its XAResource is taking part in an unfinished global transaction
        at bitronix.tm.resource.common.TransactionContextHelper.requeue(TransactionContextHelper.java:118)
        at bitronix.tm.resource.jdbc.JdbcPooledConnection.release(JdbcPooledConnection.java:146)
        ... 14 more

Am i missing something, any help will be appreciated.

Thanks
Vijay
Reply | Threaded
Open this post in threaded view
|

Re: UserTransaction commit - can't close the Connection

Ludovic Orban
Administrator
This exception is thrown when you try to close a connection that is still used by another transaction, either suspended or running in another thread.

I see RMI calls in you stack trace, what are you trying to accomplish with it as I suspect it to be part of the problem due to its threading model.
Reply | Threaded
Open this post in threaded view
|

Re: UserTransaction commit - can't close the Connection

Vijay Pandey
Hi Ludovic,

This is how the applications are set up.

a) We have an RMI application that uses BTM as the transaction manager.

b) Another java application running in different JVM gets hold of the RemoteObject from "a" and sends the request for the business process to execute.

c) The request coming from "b" are from different thread.

d) I also printed the thread name and thread group on the RMI application side and their names are different, not sure why this error?

Thanks
Vijay
Ludovic Orban wrote
This exception is thrown when you try to close a connection that is still used by another transaction, either suspended or running in another thread.

I see RMI calls in you stack trace, what are you trying to accomplish with it as I suspect it to be part of the problem due to its threading model.
Reply | Threaded
Open this post in threaded view
|

Re: UserTransaction commit - can't close the Connection

Ludovic Orban
Administrator
This description is not very helpful.

What are a and b ? What kind of calls are propagated via RMI ?
Reply | Threaded
Open this post in threaded view
|

Re: UserTransaction commit - can't close the Connection

Vijay Pandey
Hi Ludovic,

Ok will try to explain in more detail.

This is how the applications are set up.

a) We have an RMI java application that uses BTM as the transaction manager along with Hibernate 3.1.3. The database we are using is DB2 9.5 . This remote object is bound to the InitialContext through RMI Registry fo eg.

LocateRegistry.createRegistry(10001);

then

Naming.rebind(<<service name>>,<<java object>>);

b)Another java application running in different JVM will get hold of the Remote Object through

Naming.lookup(<<service name>>);

This application will have java jobs(Quartz application) running in different thread that will invoke methods on this RMI object which is present as a singleton object in this application.

c) I also printed the thread name and thread group on the RMI application side and their names are different, not sure why this error?

Thanks
Vijay


Ludovic Orban wrote
This description is not very helpful.

What are a and b ? What kind of calls are propagated via RMI ?
Reply | Threaded
Open this post in threaded view
|

Re: UserTransaction commit - can't close the Connection

Ludovic Orban
Administrator
The interesting part of your application is how the transaction manager is used.

When doing remote calls, you have to make sure all transactional resources are used only for the duration of the call. You cannot open a connection in a remote call, start a transaction in another one and finally commit and close in a third one for instance, all of that must happen in a single call.

The reason is that you have no control over the RMI threading and transaction management is working on a thread basis, meaning that a transaction can never span over two threads as per JTA spec.
Reply | Threaded
Open this post in threaded view
|

Re: UserTransaction commit - can't close the Connection

Vijay Pandey
We are making sure that all transactional resources are used only for the duration of the call.

This is how any RMI call happends in our application

Object a = RemoteObject

Object b = a.get Another Remote Object ( which returns a new Object always)

then we call b.process() -- Here in this process method we have this piece of code.

UserTransaction ut = TransactionManagerServices.getTransactionManager();

ut.begin();

//do some processing--

if no exception then
ut.commit()

else

ut.rollback();

This all happens in a single call.

What i am thinking is to test the same by doing some pooling on Thread for eg

for every call to Remote Object, i create a set of Threads which will be pooled and used -- by making use of Jakarta Commons Pool

Thanks
Vijay




Ludovic Orban wrote
The interesting part of your application is how the transaction manager is used.

When doing remote calls, you have to make sure all transactional resources are used only for the duration of the call. You cannot open a connection in a remote call, start a transaction in another one and finally commit and close in a third one for instance, all of that must happen in a single call.

The reason is that you have no control over the RMI threading and transaction management is working on a thread basis, meaning that a transaction can never span over two threads as per JTA spec.
Reply | Threaded
Open this post in threaded view
|

Re: UserTransaction commit - can't close the Connection

Ludovic Orban
Administrator
Please collect debug logs and send the file here, I'll have a look at it. Make sure thread names are included !