users@glassfish.java.net

Re: Non-Transactional MDB Unable to write message to non-txn queue

From: <glassfish_at_javadesktop.org>
Date: Tue, 18 Sep 2007 14:42:41 PDT

Siva,

This problem occurred again in another testing. It is very random from what I can tell.
The queue we are writing to is created in the onMessage when call to Stateless Session bean is complete (the session bean runs in its own txn since the method we are calling has REQUIRED txn attribute). After the bean call returns successfully, we write to the queue to initiate next step in our state machine. A non transacted session is created from the connection explicitly (i.e. connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE)). So I can't figure out why glassfish thinks that a transaction exists and it has been not started? This happens on 3-4% of all messages processed by this MDB. This again points to some kind of race condition and potential threading issues.

Shown below are ejb-jar.xml and sun-ejb-jar.xml for this MDB. We are using annotations to mark transaction for this MDB. We do not override txn in the ejb-jar.xml. Could this be a problem?

 The annotation is shown here:

@MessageDriven (name="messagedriven.OrderMatcherMdb",
        activationConfig = {
            @ActivationConfigProperty(propertyName="destinationType",
                    propertyValue="javax.jms.Queue"),
            @ActivationConfigProperty(propertyName="acknowledgeMode",
                    propertyValue="Auto-acknowledge")
})
@TransactionManagement(value=TransactionManagementType.CONTAINER)
@TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)


ejb-jar.xml
---------------
<?xml version="1.0" encoding="UTF-8"?>^M
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"^M
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"^M
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee^M
                  http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"^M
              version="3.0">^M
        <enterprise-beans>^M
                <message-driven>^M
                        <ejb-name>messagedriven.OrderMatcherMdb</ejb-name>^M
                        <ejb-class>com.foliotrade.op.ejb.messagedriven.OrderMatcherMdb</ejb-class>^M
                        <!-- Uncomment to override values set in annotations.^M
                        <messaging-type>javax.jms.MessageListener</messaging-type>^M
                        <transaction-type>Container</transaction-type>^M
                        <message-destination-type>javax.jms.Queue</message-destination-type>^M
                        <activation-config>^M
                                <activation-config-property>^M
                                        <activation-config-property-name>destinationType</activation-config-property-na
me>^M
                                        <activation-config-property-value>javax.jms.Queue</activation-config-property-v
alue>^M
                                </activation-config-property>^M
                                <activation-config-property>^M
                                        <activation-config-property-name>acknowledgeMode</activation-config-property-na
me>^M
                                        <activation-config-property-value>Auto-acknowledge</activation-config-property-
value>^M
                                         Valid values are: Dups-ok-acknowledge, Client-acknowledge^M
                                </activation-config-property>^M
                        </activation-config>^M
                        -->^M
                </message-driven>^M
        </enterprise-beans>^M
        <!-- Uncomment to override values set in annotations.^M
        <assembly-descriptor>^M
                <container-transaction>^M
                        <method>^M
                                <ejb-name>messagedriven.OrderMatcherMdb</ejb-name>^M
                                <method-name>onMessage</method-name>^M
                        </method>^M
                        <trans-attribute>NotSupported</trans-attribute>^M
                </container-transaction>^M
        </assembly-descriptor>^M
        -->^M
</ejb-jar>


sun-ejb-jar.xml
----------------------
<?xml version="1.0" encoding="UTF-8"?>^M
^M
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" ^M
                                                "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">^M
^M
<sun-ejb-jar>^M
    <enterprise-beans>^M
        <ejb>^M
            <ejb-name>messagedriven.OrderMatcherMdb</ejb-name>^M
            <jndi-name>jms/jms.queue.fixReplyQueue</jndi-name>^M
            <!-- Using defaults^M
            <mdb-resource-adapter>^M
                <resource-adapter-mid>jmsra</resource-adapter-mid>^M
                <activation-config>^M
                        <activation-config-property>^M
                                <activation-config-property-name>SendUndeliverableMsgsToDMQ</activation-config-property
-name>^M
                                <activation-config-property-value>true</activation-config-property-value>^M
                        </activation-config-property>^M
                        <activation-config-property>^M
                                <activation-config-property-name>EndpointExceptionRedeliveryAttempts</activation-config
-property-name>^M
                                <activation-config-property-value>1</activation-config-property-value>^M
                        </activation-config-property>^M
                        <activation-config-property>^M
                                <activation-config-property-name>EndpointExceptionRedeliveryInterval</activation-config
-property-name>^M
                                <activation-config-property-value>15</activation-config-property-value>^M
                        </activation-config-property>^M
                </activation-config>^M
            </mdb-resource-adapter>^M
            -->^M
                        <mdb-connection-factory>^M
                                <jndi-name>jms/jms.connection.fixReplyQFactory</jndi-name>^M
                                <default-resource-principal>^M
                                        <name>guest</name>^M
                                        <password>guest</password>^M
                                </default-resource-principal>^M
                        </mdb-connection-factory>^M
                        <bean-pool>^M
                                <max-pool-size>1</max-pool-size>^M
                                <steady-pool-size>1</steady-pool-size>^M
                                <resize-quantity>2</resize-quantity>^M
                        </bean-pool>^M
        </ejb>^M
    </enterprise-beans>^M
</sun-ejb-jar>
------

Any hints to as to what might be going is highly appreciated. I have debugged via Glassfish source code and can't seem to pin point under what scenario it occurs (also if it is a race condition problem with threading, then debugger slows things down and it will be very difficult to replicate conditions).

Another thing I am thinking was to mark txn explicitly in the ejb-jar.xml i.e. override the annotation. Let me know if this is worth pursuing.

regards,
Sanjay
[Message sent by forum member 'sanjaydwivedi' (sanjaydwivedi)]

http://forums.java.net/jive/thread.jspa?messageID=235918