Discussions

EJB programming & troubleshooting: How to implement a timeout ?

  1. How to implement a timeout ? (6 messages)

    Hi All,

    When calling another bean from a bean how to implement a timeout? Suppose
    Bean A is calling a method on Bean B. But Bean B is taking too much time to process the request, so I want to timeout the method. (I am using Weblogic5.1) .

    ( I have tried to use container managed transaction. And when I have set the value of trans-timeout-seconds in weblogic-ejb-jar.xml - I have got a message that transaction has been rolled backed because of timeout - but my control hasn't returned to Bean A. After the Bean B 's method is completed then only I have got the control back. But I want control to be returned to me immediately after timeout).

    Waiting for your reply...

    Thanks
    Srijeeb.

    Threaded Messages (6)

  2. How to implement a timeout ?[ Go to top ]

    FYI

    Bean A and Bean B both are stateless session Bean.

    -Thanks
    Srijeeb.
  3. How to implement a timeout ?[ Go to top ]

    One solution I did a while ago was to implement a helper class, called by Bean A, that spawns a thread to implement the second call. The helper class can then wait the specified timeout period. This was implemented on WL 4.51.
  4. How to implement a timeout ?[ Go to top ]

    Hi David,

    Thanks for your sol.I have also thought about that solution. But Weblogic recommends (basically J2EE spec ) not to spawn external threads from Beans. If I use Helper class - then also the Thread (external thread created by programmer)will be spawned from the same process.

    -Thanks
    Srijeeb.
  5. How to implement a timeout ?[ Go to top ]

    If your bussiness logic allows it, you could set the transaction attribute of bean B to "requires new". That way, only the transaction for bean B will be rolled back when timeout happens and the control will return to the calling bean A which is outside the transaction scope of bean B.

    Pranab
  6. How to implement a timeout ?[ Go to top ]

    Hi Pranab,

    My Bean A is not in any transaction. Currently the transaction attribute of the method of Bean B is set to "Required".So, if I set the transaction attribute of the method of Bean B as "RequiresNew" , I think the effect will be same. Because if the Client is not in Transaction the effect of "Required" and "RequiresNew" are same. Do I need to put the caller method (of Bean A) also in Transaction? But my Caller method (of Bean A) doesn't need any transaction according to Business needs.

    Thanks
    Srijeeb.
  7. How to implement a timeout ?[ Go to top ]

    Srijeeb,

    You are right. However, it seems like your bean A method is spawning a transaction. What is transaction attribute of your bean A method set to any way? If it's not set to anything, by default the container might be starting a tranaction. I am not sure what the ejb spec says about the default transaction behaviour.

    Pranab