1 Reply Latest reply on Aug 20, 2004 12:38 PM by Adrian Brock

    Sending JMS from session bean and transaction time-out

    chris_pollentier Newbie

      Could anyone help me please ? I have some strange behaviour when sending jms_messages from whitin a session bean with CMT.

      I have written some small session bean and a test client to illustrate the problem.
      The code is posted below, togheter with configuration related to jms
      (sorry for the long postings, but since I have no clue what is going on I posted a lot of configuration)

      We are running on jboss-3.2.3. I also tried jboss-3.2.4, but the result is the same.
      OS = Linux (fedora core 2)
      Database = mysql 4.0.18

      The situation is the following:
      Inside the session bean, I create a loop that sends one message every second to some queue. All messages are sent within one transaction.
      I send in total 100 messages (in 100 seconds) and I put my transaction timeout to 90 seconds.
      What happens is that the transaction times out, but still the JMSSender is able to send messages to the queue.
      When the transaction ends, no exception is thrown to indicate that the transaction is rolled back.

      The Session bean:

      
      package com.kiala.kserver.synch;
      
      import org.apache.log4j.Logger;
      
      import javax.jms.*;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.ejb.SessionBean;
      import javax.ejb.EJBException;
      import javax.ejb.SessionContext;
      import java.rmi.RemoteException;
      
      /**
       * A simple session bean to test the behaviour of sending JMS messages
       * when a transaction timeout occurs.
       *
       * @ejb.bean type="Stateless"
       * name="TestTransaction"
       * display-name="Test Transaction Session Bean"
       * jndi-name="ejb/kserver/TestTransaction"
       * local-jndi-name="ejb/kserver/TestTransactionLocal"
       * view-type="both"
       *
       * @ejb.util generate="physical"
       *
       * @ejb.resource-ref res-ref-name = "jms/QueueConnectionFactory"
       * res-type = "javax.jms.QueueConnectionFactory"
       * res-auth = "Container"
       * @jboss.resource-ref res-ref-name = "jms/QueueConnectionFactory"
       * jndi-name = "java:/JmsXA"
       *
       * @ejb.transaction type="Required"
       *
       */
      public class TestTransactionSessionBean implements SessionBean {
       public void ejbActivate() throws EJBException, RemoteException {}
       public void ejbPassivate() throws EJBException, RemoteException {}
       public void ejbRemove() throws EJBException, RemoteException {}
       public void setSessionContext(SessionContext sessionContext) throws EJBException, RemoteException {}
       public static Logger logger = Logger.getLogger(TestTransactionSessionBean.class.getName());
      
       private QueueConnection getQueueConnection () throws NamingException, JMSException {
       InitialContext initialContext = null;
      
       try {
       initialContext = new InitialContext() ;
       } catch (NamingException ne) {
       logger.fatal("Cannot get initial context", ne);
       }
      
       System.out.println("Getting connection");
       QueueConnectionFactory queueConnectionFactory = queueConnectionFactory = (QueueConnectionFactory) initialContext.lookup("java:/comp/env/jms/QueueConnectionFactory");
       return queueConnectionFactory.createQueueConnection();
       }
      
       /**
       * @ejb.interface-method view-type = "both"
       */
       public void testTxJMS() {
       QueueConnection connection = null;
       QueueSession session = null;
       QueueSender sender = null;
       try {
       connection = getQueueConnection();
       session = connection.createQueueSession(true, QueueSession.AUTO_ACKNOWLEDGE);
       Queue queue = (Queue)new InitialContext().lookup("queue/TransactionTestQueue");
       connection.start();
       for (int i = 0; i < 100; i++) {
       sender = session.createSender(queue);
      
       Message msg = session.createTextMessage("TestMessage " + i);
       sender.send(msg);
       System.out.println("Sent " + (i+1) + " messages");
      
       try {
       sender.close();
       } catch (Exception e) {
       e.printStackTrace();
       }
       waitWithoutSleeping(1);
       }
       } catch(NamingException n) {
       logger.error (n);
       } catch(JMSException e) {
       logger.error(e);
       } finally {
       try {
       sender.close();
       } catch(Exception e) {
       e.printStackTrace();
       }
       try {
      
       session.close();
       } catch (Exception e) {
       e.printStackTrace();
       }
      
       try {
       connection.close();
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
       }
      
       /***
       * This method simulates a sleep, without suspending the Thread
       *
       * @param seconds the number of seconds to wait
       */
       private void waitWithoutSleeping(int seconds) {
       long millisToWait = seconds * 1000;
       long startT = System.currentTimeMillis();
       long currentT = System.currentTimeMillis();
       while (currentT - startT < millisToWait) {
       currentT = System.currentTimeMillis();
       }
       }
      }
      


      Since my transaction timeout is set to 90 seconds, the timeout occurs occurs when sending the 90th message.
      However, after that the session bean just continues to send messages.

      The server log contains the following (using TRACE for org.jboss.tm)

      
      14:52:02,146 TRACE [jboss.tm.TxManager] tx timeout is now: 0s
      14:52:02,146 TRACE [jboss.tm.TransactionImpl] Created new instance for tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//9, BranchQual=]
      14:52:02,147 TRACE [jboss.tm.TxManager] began tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//9, BranchQual=]
      14:52:02,149 TRACE [jboss.tm.TransactionImpl] Committing, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//9, BranchQual=], status=STATUS_ACTIVE
      14:52:02,149 TRACE [jboss.tm.TransactionImpl] Before completion done, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//9, BranchQual=], status=STATUS_ACTIVE
      14:52:02,149 TRACE [jboss.tm.TransactionImpl] Zero phase commit: No resources.
      14:52:02,149 TRACE [jboss.tm.TransactionImpl] Committed OK, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//9, BranchQual=]
      14:52:02,149 TRACE [jboss.tm.TxManager] suspended tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//9, BranchQual=]
      14:52:02,149 TRACE [jboss.tm.TxManager] tx timeout is now: 90s
      14:52:02,492 TRACE [jboss.tm.TxManager] tx timeout is now: 0s
      14:52:02,492 TRACE [jboss.tm.TransactionImpl] Created new instance for tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=]
      14:52:02,492 TRACE [jboss.tm.TxManager] began tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=]
      14:52:02,493 INFO [STDOUT] Getting connection
      14:52:02,494 TRACE [jboss.tm.TransactionImpl] enlistResource(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=] status=STATUS_ACTIVE
      14:52:02,495 TRACE [jboss.tm.TransactionImpl] startResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1]) entered: SpyXAResource[session=SpySession@5066606[tx=true txid=null XA RUNNING connection=Connection@20772999[token=ConnectionToken:ID:1/2ce7b433f4bad4ecd4b462e2ea42e6ff rcvstate=STOPPED]]] flags=0
      14:52:02,495 TRACE [jboss.tm.TransactionImpl] startResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1]) leaving: SpyXAResource[session=SpySession@5066606[tx=true txid=XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1] XA RUNNING connection=Connection@20772999[token=ConnectionToken:ID:1/2ce7b433f4bad4ecd4b462e2ea42e6ff rcvstate=STOPPED]]] flags=0
      14:52:02,495 TRACE [jboss.tm.TransactionImpl] registerSynchronization(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=] status=STATUS_ACTIVE
      14:52:02,496 INFO [STDOUT] Sent 1 messages
      14:52:03,496 INFO [STDOUT] Sent 2 messages
      14:52:04,496 INFO [STDOUT] Sent 3 messages
      ...
      4:53:30,882 INFO [STDOUT] Sent 89 messages
      14:53:31,882 INFO [STDOUT] Sent 90 messages
      14:53:32,495 WARN [jboss.tm.TransactionImpl] Transaction TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=] timed out. status=STATUS_ACTIVE
      14:53:32,882 INFO [STDOUT] Sent 91 messages
      14:53:33,884 INFO [STDOUT] Sent 92 messages
      ...
      14:53:41,123 INFO [STDOUT] Sent 99 messages
      14:53:42,123 INFO [STDOUT] Sent 100 messages
      14:53:43,123 TRACE [jboss.tm.TransactionImpl] delistResource(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=] status=STATUS_MARKED_ROLLBACK
      14:53:43,123 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1]) entered: SpyXAResource[session=SpySession@5066606[tx=true txid=XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1] XA RUNNING connection=Connection@20772999[token=ConnectionToken:ID:1/2ce7b433f4bad4ecd4b462e2ea42e6ff rcvstate=STOPPED]]] flag=33554432
      14:53:43,123 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1]) leaving: SpyXAResource[session=SpySession@5066606[tx=true txid=null XA RUNNING connection=Connection@20772999[token=ConnectionToken:ID:1/2ce7b433f4bad4ecd4b462e2ea42e6ff rcvstate=STOPPED]]] flag=33554432
      14:53:43,124 TRACE [jboss.tm.TransactionImpl] rollback(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=] status=STATUS_MARKED_ROLLBACK
      14:53:43,124 TRACE [jboss.tm.TransactionImpl] endresources(0): state=2
      14:53:43,124 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1]) entered: SpyXAResource[session=SpySession@5066606[tx=true txid=null XA RUNNING connection=Connection@20772999[token=ConnectionToken:ID:1/2ce7b433f4bad4ecd4b462e2ea42e6ff rcvstate=STOPPED]]] flag=67108864
      14:53:43,124 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=1]) leaving: SpyXAResource[session=SpySession@5066606[tx=true txid=null XA RUNNING connection=Connection@20772999[token=ConnectionToken:ID:1/2ce7b433f4bad4ecd4b462e2ea42e6ff rcvstate=STOPPED]]] flag=67108864
      14:53:43,124 TRACE [jboss.tm.TxManager] suspended tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=]
      14:53:43,124 TRACE [jboss.tm.TransactionImpl] Created new instance for tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=]
      14:53:43,124 TRACE [jboss.tm.TxManager] began tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=]
      14:53:43,131 TRACE [jboss.tm.TransactionImpl] enlistResource(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=] status=STATUS_ACTIVE
      14:53:43,131 TRACE [jboss.tm.TransactionImpl] startResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=1]) entered: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flags=0
      14:53:43,132 TRACE [jboss.tm.TransactionImpl] startResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=1]) leaving: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flags=0
      14:53:43,132 TRACE [jboss.tm.TransactionImpl] registerSynchronization(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=] status=STATUS_ACTIVE
      14:53:43,133 TRACE [jboss.tm.TransactionImpl] Committing, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=], status=STATUS_ACTIVE
      14:53:43,133 TRACE [jboss.tm.TransactionImpl] calling sync 0, org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TxRemover@3abc87
      14:53:43,133 TRACE [jboss.tm.TransactionImpl] Before completion done, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=], status=STATUS_ACTIVE
      14:53:43,133 TRACE [jboss.tm.TransactionImpl] endresources(0): state=1
      14:53:43,133 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=1]) entered: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flag=67108864
      14:53:43,134 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=1]) leaving: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flag=67108864
      14:53:43,134 TRACE [jboss.tm.TransactionImpl] One phase commit: One resource.
      14:53:43,134 TRACE [jboss.tm.TransactionImpl] Committing resources, resourceStates[0]=3
      14:53:43,138 TRACE [jboss.tm.TransactionImpl] Committed OK, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=]
      14:53:43,138 TRACE [jboss.tm.TxManager] commited tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//11, BranchQual=]
      14:53:43,138 TRACE [jboss.tm.TxManager] resumed tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=]
      14:53:43,138 TRACE [jboss.tm.TxManager] suspended tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=]
      14:53:43,139 TRACE [jboss.tm.TransactionImpl] Created new instance for tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=]
      14:53:43,139 TRACE [jboss.tm.TxManager] began tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=]
      14:53:43,139 TRACE [jboss.tm.TransactionImpl] enlistResource(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=] status=STATUS_ACTIVE
      14:53:43,140 TRACE [jboss.tm.TransactionImpl] startResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=1]) entered: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flags=0
      14:53:43,140 TRACE [jboss.tm.TransactionImpl] startResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=1]) leaving: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flags=0
      14:53:43,140 TRACE [jboss.tm.TransactionImpl] registerSynchronization(): Entered, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=] status=STATUS_ACTIVE
      14:53:43,141 TRACE [jboss.tm.TransactionImpl] Committing, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=], status=STATUS_ACTIVE
      14:53:43,142 TRACE [jboss.tm.TransactionImpl] calling sync 0, org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TxRemover@1bad2e8
      14:53:43,142 TRACE [jboss.tm.TransactionImpl] Before completion done, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=], status=STATUS_ACTIVE
      14:53:43,142 TRACE [jboss.tm.TransactionImpl] endresources(0): state=1
      14:53:43,142 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=1]) entered: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flag=67108864
      14:53:43,142 TRACE [jboss.tm.TransactionImpl] endResource(XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=1]) leaving: org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@121e5a flag=67108864
      14:53:43,142 TRACE [jboss.tm.TransactionImpl] One phase commit: One resource.
      14:53:43,142 TRACE [jboss.tm.TransactionImpl] Committing resources, resourceStates[0]=3
      14:53:43,143 TRACE [jboss.tm.TransactionImpl] Committed OK, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=]
      14:53:43,143 TRACE [jboss.tm.TxManager] commited tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//12, BranchQual=]
      14:53:43,143 TRACE [jboss.tm.TxManager] resumed tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=]
      14:53:43,143 TRACE [jboss.tm.TransactionImpl] failed after completion
      java.lang.NullPointerException
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TxRemover.afterCompletion(TxConnectionManager.java:626)
       at org.jboss.tm.TransactionImpl.doAfterCompletion(TransactionImpl.java:1398)
       at org.jboss.tm.TransactionImpl.rollback(TransactionImpl.java:463)
       at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:448)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:324)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:148)
       at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:120)
       at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
       at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
       at org.jboss.ejb.Container.invoke(Container.java:723)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:185)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
       at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
       at sun.rmi.transport.Transport$1.run(Transport.java:148)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
       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:536)
      14:53:43,145 TRACE [jboss.tm.TxManager] suspended tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=bastard.dev.kiala.com//10, BranchQual=]
      14:53:43,145 TRACE [jboss.tm.TxManager] tx timeout is now: 90s
      


      When all messages are sent and the transaction should be rolled back, then nothing happens.
      The method ends without throwing any exception to the client.

      (In case you were wondering: the waitWithoutSleeping(int seconds) is added because I did not want my Thread to go to sleep since I was reproducting a problem of our production system.
      If I use Thread.sleep(..), then we get an interrupedException when the tx times out.)

      When I create a new JMSSession for each message, then I do get an exception after timeout,
      but the exception message does not say anything about a transaction timeout:

      12:22:43,631 ERROR [adapter.jms.JmsSessionFactoryImpl] could not create session
      javax.resource.ResourceException: Interrupted while requesting permit! Waited 0 ms, invocation time: 1092824563628
      at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:261)
      at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:534)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:444)
      at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:312)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:496)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:887)
      at org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.allocateConnection(JmsSessionFactoryImpl.java:369)
      at org.jboss.resource.adapter.jms.JmsSessionFactoryImpl.createQueueSession(JmsSessionFactoryImpl.java:137)
      at com.kiala.kserver.synch.TestTransactionSessionBean.testTxJMS(TestTransactionSessionBean.java:137)

      Config files:

      jms-ds.xml:
      
       <!-- The JMS provider loader -->
       <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
       name="jboss.mq:service=JMSProviderLoader,name=JMSProvider">
       <attribute name="ProviderName">DefaultJMSProvider</attribute>
       <attribute name="ProviderAdapterClass">
       org.jboss.jms.jndi.JNDIProviderAdapter
       </attribute>
       <!-- The queue connection factory -->
       <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
       <!-- The topic factory -->
       <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
       <!-- Uncomment to use HAJNDI to access JMS
       <attribute name="Properties">
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
       java.naming.provider.url=localhost:1100
       </attribute>
       -->
       </mbean>
      
       <!-- The server session pool for Message Driven Beans -->
       <mbean code="org.jboss.jms.asf.ServerSessionPoolLoader"
       name="jboss.mq:service=ServerSessionPoolMBean,name=StdJMSPool">
       <depends optional-attribute-name="XidFactory">jboss:service=XidFactory</depends>
       <attribute name="PoolName">StdJMSPool</attribute>
       <attribute name="PoolFactoryClass">
       org.jboss.jms.asf.StdServerSessionPoolFactory
       </attribute>
       </mbean>
      
       <!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->
       <tx-connection-factory>
       <jndi-name>JmsXA</jndi-name>
       <xa-transaction/>
       <adapter-display-name>JMS Adapter</adapter-display-name>
       <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
       <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/DefaultJMSProvider</config-property>
       <max-pool-size>50</max-pool-size>
       <security-domain-and-application>JmsXARealm</security-domain-and-application>
       </tx-connection-factory>
      


      Datasource configuration:


      
      <datasources>
       <local-tx-datasource>
       <jndi-name>kialapointDS</jndi-name>
       <connection-url>jdbc:mysql://localhost/kp?autoReconnect=true</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
       <user-name>xx</user-name>
       <password>xx</password>
       <min-pool-size>0</min-pool-size>
       <max-pool-size>90</max-pool-size>
       <blocking-timeout-millis>5000</blocking-timeout-millis>
       <idle-timeout-minutes>15</idle-timeout-minutes>
       <new-connection-sql>select 1</new-connection-sql>
       <check-valid-connection-sql>select 1</check-valid-connection-sql>
       </local-tx-datasource>
      </datasources>
      


      Extract from jboss-service.xml

       <mbean code="org.jboss.mq.server.jmx.Queue"
       name="jboss.mq.destination:servnsactionTestQueueice=Queue,name=TransactionTestQueue">
       <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
       </mbean>
      
       <mbean code="org.jboss.tm.TransactionManagerService"
       name="jboss:service=TransactionManager"
       xmbean-dd="resource:xmdesc/TransactionManagerService-xmbean.xml">
       <attribute name="TransactionTimeout">90</attribute>
      
       <depends optional-attribute-name="XidFactory">jboss:service=XidFactory</depends>
       </mbean>
      


      jms-ds.xml

      <?xml version="1.0" encoding="UTF-8"?>
      
      <connection-factories>
      
       <!-- ==================================================================== -->
       <!-- JMS Stuff -->
       <!-- ==================================================================== -->
      
       <!-- The JMS provider loader -->
       <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
       name="jboss.mq:service=JMSProviderLoader,name=JBossMQProvider">
       <attribute name="ProviderName">DefaultJMSProvider</attribute>
       <attribute name="ProviderAdapterClass">
       org.jboss.jms.jndi.JBossMQProvider
       </attribute>
       <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
       <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
       </mbean>
      
       <!-- The server session pool for Message Driven Beans -->
       <mbean code="org.jboss.jms.asf.ServerSessionPoolLoader"
       name="jboss.mq:service=ServerSessionPoolMBean,name=StdJMSPool">
       <depends optional-attribute-name="XidFactory">jboss:service=XidFactory</depends>
       <attribute name="PoolName">StdJMSPool</attribute>
       <attribute name="PoolFactoryClass">
       org.jboss.jms.asf.StdServerSessionPoolFactory
       </attribute>
       </mbean>
      
       <!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->
      
       <tx-connection-factory>
      
       <jndi-name>JmsXA</jndi-name>
      
       <xa-transaction/>
      
       <adapter-display-name>JMS Adapter</adapter-display-name>
      
       <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
       <!-- The pool size of concurrent JMS sessions -->
       <max-pool-size>50</max-pool-size>
       <security-domain-and-application>JmsXARealm</security-domain-and-application>
      
       </tx-connection-factory>
      </connection-factories>
      
      


      Extract from mysql-jdbc2-service.xml

       <mbean code="org.jboss.mq.pm.jdbc2.PersistenceManager"
       name="jboss.mq:service=PersistenceManager">
       <depends optional-attribute-name="ConnectionManager">jboss.jca:service=LocalTxCM,name=kialapointDS</depends>
       <attribute name="SqlProperties">
      


      Can anyone tell me if my code wrong ? Is this a bug in jboss ?
      (we should get an exception on the client right ?)

      Another question aside: Is the transaction timeout (see extract of jboss-service.xml above) a global transaction timout, or is it an idle transaction timeout.
      What I mean is: will the transaction timeout occur exactly after the specified number of seconds,
      or if the transaction is idle for the specified number of seconds ?.
      When I trace the logs from mysql, I can see that the 'insert into jms_messages' statements are sent only when the transaction commits, so I do not know if the transactions times out because it is idle for 90 seconds, or because it has started 90 seconds ago.

      Extract of the test client to trigger the test:

       try {
       TestTransaction tx = TestTransactionUtil.getHome(environment).create();
       tx.testTxJMS();
       System.out.println("Method returned");
       } catch (Exception e) {
       e.printStackTrace();
       }
      



        • 1. Re: Sending JMS from session bean and transaction time-out
          Adrian Brock Master

          The reason is that the session stores messages sent in a transaction
          locally. It doesn't send them to the server until the commit
          (which never happens because the timeout forces a rollback).

          1) connection.createSession(...); // enlists session in transaction
          2) add messages to the session (it is transacted)
          3) timeout
          4) keeps adding messages to the session
          5) When finished, try to commit (which would send the messages to the server), but the timeout forces a rollback

          In other words:
          A createSession() or commit() will fail if a timeout has occurred.
          A send will not, because it is not communicating with the server
          (it is just accumulating messages waiting for a commit).