Discussions

EJB programming & troubleshooting: Forcing and EJB to return from a method

  1. Forcing and EJB to return from a method (1 messages)

    Hi,

    I have an EJB stateless session bean (EJB 2.0) running on a weblogic 7.0 SP 4 server. I would like to know if it is possible to force a a return from a stateless session bean method without changing code ?. The problem is that I have to access and external EJB (can´t change source code), sometimes the method takes X mins/hours to return. Is there a way to tell weblogic to "timeout" after X seconds from a method/ejb call.

    I tried modifying the descriptors of the EJB (ejb-jar.xml and weblogic-ejb.xml) to apply demarcation transaction, but no luck. Any help would be appreciated.
    Here are the XML files:

    ejb.xml
    =======
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

    <ejb-jar>
        <display-name>EJBTimeout</display-name>
        <enterprise-beans>
          <session>
    <display-name>EJBTimeout</display-name>
    <ejb-name>EJBTimeout</ejb-name>
    <home>BeanHome</home>
    <remote>BeanRemote</remote>
    <ejb-class>Bean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
          </session>
        </enterprise-beans>

        <assembly-descriptor>
        
       <container-transaction>
       
       <method>
       <ejb-name>EJBTimeout</ejb-name>
       <method-name>payInvoice()</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
        </container-transaction>
        </assembly-descriptor>
       
      </ejb-jar>

    weblogic-ejb.xml
    ================
    <?xml version="1.0"?>

    <!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN' 'http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd'>


    <weblogic-ejb-jar>
        <weblogic-enterprise-bean>
          <ejb-name>EJBTimeout</ejb-name>
     
    <transaction-descriptor>
    <trans-timeout-seconds>20</trans-timeout-seconds>
    </transaction-descriptor>
          <jndi-name>statelessSession.EJBTimeout</jndi-name>

    </weblogic-enterprise-bean>

      </weblogic-ejb-jar>


    Thanks for reading :-)

    Gerardo
  2. not that I'm aware of.

    You need to think of this in terms of java threads - execution of a thread has passed through the ejb container into your bean code, and then onto whatever else from there - RDBMS driver for example. Weblogic doesn't have control over what the thread does until it gets back from whatever it's doing. It could interrupt the thread, but could be problematic for whatever code thread was currently executing - leaving resources unfreed etc.

    There's nothing in the ejb specs to address this - changing the descriptors will not help. The trans-timeout setting won't help either - it just tells weblogic to abort the transaction if the thread spent longer than x seconds inside your bean, rather than forcing the call to return after x seconds.

    I think you need to look more closely at why the call is taking so long. Are you calling some other resource ? Is there a deadlock situation occuring ? Something is going wrong if a call is taking this long - if you can find and fix this you'll have addressed the source of the problem, rather than working around it.