Announcement Announcement Module
No announcement yet.
Accessing EJBs from user created thread Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing EJBs from user created thread


    I'm migrating to Spring and have lots of old EJBs that still needs to be EJBs. For several reasons, I really need the calls to the EJB to be asynchronous, but I find no way to do it.

    The call originally comes from the web container (hessian web service), and I have been trying to use TaskExecutor, normal Threads etc, but the container (OC4J) complains that the thread is in a non application context of course.

    How can I spawn off threads in Spring that are in the correct (EJB?) context? Or maybe there is a way to have a servlet return immediately?

    Best regards

  • #2
    In general,
    it's a good practice to use jms if you want to do asynchronous activities.
    This means that:
    1. Your servlet sends a message in a queue
    2. A Message Driven Bean intercepts the message and, based on its content, may invoke the correct EJB

    Another (and probably more scalable) solution may be creating a queue for each session bean, and hence, an mdb for each one.
    In order to try both the solutions, I suggest you to implement a service locator on the web tier.
    Anyway, you have to cope with eventual return value, which should be persisted somewhere.