Transaction isolation problem!
clebert.suconic Aug 10, 2005 12:49 AMI'm having an issue that I don't know if it's a bug or a JMS configuration problem.
I have a testcase which is calling a Statefull Session Bean.
Them I'm sending a JMS message, supposelly using XA. Here is the code for the lookup in the Stateless Session Bean, Bean Managed Transaction:
public void setSessionContext(SessionContext sessionContext) { this.sessionContext = sessionContext; try { // the homes are available via EJB links Context context = new InitialContext(); queueConnFactory = (QueueConnectionFactory) context.lookup("java:/JmsXA"); queue = (Queue) context.lookup("queue/TestQueue"); System.out.println("queue = " + queue.toString()); } catch( NamingException e ) { throw new EJBException("Failure looking up home" + e); } }
The method which is sending the message:
public void testSend(String strmessage) { String itemId = null; QueueConnection queueConn = null; QueueSession queueSess = null; //Check for large orders try { UserTransaction trans = sessionContext.getUserTransaction(); trans.begin(); int originalValue = MDBSimpleListener.count; queueConn = queueConnFactory.createQueueConnection(); queueSess = queueConn.createQueueSession(true, 0); QueueSender queueSender = queueSess.createSender(queue); TextMessage message; try{ message = queueSess.createTextMessage(); message.setText(strmessage); System.out.println("message was sent" + message); queueSender.send(message); Thread.sleep(1000); if (originalValue!=MDBSimpleListener.count) { throw new RuntimeException("Value changed"); } trans.commit(); Thread.sleep(1000); if (originalValue==MDBSimpleListener.count) { throw new RuntimeException("Value not changed"); } } finally { if( queueConn != null ) queueConn.close(); if( queueSess != null ) queueSess.close(); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException (e); } }
The only thing done at the MDB (MDBSimpleListener) is to increment a static value, and the value is being changed before the commit of the transaction. In other words I'm getting the first runtime exception (Value changed).
So, if someone think this a bug it would be easy to add this testcase to the testsuite.
If this is a configuration issue, any idea in what is wrong?
I'm having an issue with Specj, where a MDB is getting a message before the caller releases the rows which is causing some deadlocks. That's why I have extracted this testcase.
Clebert Suconic