Help with EJB Arch: Synchronous front-end <--> Asynchronous back


EJB programming & troubleshooting: Help with EJB Arch: Synchronous front-end <--> Asynchronous back

  1. Hi folks, We are developing an application with the following characteristics: - users can invoke requests on our appl and they will expect a quick response - to obtain the information requested by the user, our application talks with Tibco using RV. This communication follows a pub/sub messaging paradigm and is asynchronous. - thus, we have a synchronous req/resp front-end and an asynch back-end.

    We would like some advice as to the best way of architecting this application. Here is our approach. Please critic and suggest alternatives.

    1. Consider an user who has requested something from our app.

    2. The user will be using a JSP based front-end. (S)he submits the request on a form and a servlet is driven.

    3. The servlet uses a session EJB and invokes one of its methods, which handles some business-specific logic.

    4. The method in the session EJB then instantiates a helper class.

    5. A method on our helper class is now driven. This method sends a message to Tibco and it provides a callback method in the helper class.

    6. The method in the helper class blocks the thread - basically, it waits.

    7. Meanwhile, Tibco does the processing and invokes the callback method (in the helper class) with the result.

    8. In the callback method, the data sent by Tibco is stored in member variables of the helper class.

    9. The callback method wakes up the blocking thread.

    10. The method in step 6 wakes up and returns the information to the session EJB.

    11. The session EJB returns the information to the invoking servlet.

    12. The servlet provides the information back to the user.

    The version of Tibco-RV that we are using is not JMS compliant.

    We keep hearing that threads should be handled very carefully in an EJB container environment, so we would like to know if the way we are handling the thread in the helper class is okay. Could we remove the helper class and do the same thread-handling in the session EJB itself?

    Can we use JMS in this solution even though our Tibco-RV does not support JMS?

    Tools: Weblogic App Server 6.1, JBuilder 5.0.

    Thanks for your advice and suggestions!

  2. We have a system working along the lines you've described: JSP-JavaBean-EJB-RV-backEnd. Everything works fine as far as I can tell. It's just not clear to me why you need to start a separate thread in some helper class called from EJB? Your web-client is waiting for response, and this response will come only after the back end completed whatever it needed to complete. I just fail to see any merit in moving the call to a separate thread: what would the calling thread do in the meantime? If you are worried about multiple requests - well that's what EJBs are for: each of them works in its own thread, not interfering with the other. We call RV send(..) method more or less directly from a special stateless session EJB.
  3. Another thread is not created from what I can see.

    This should work, but in theory is against the EJB spec. I wouldn't worry about that if it works though.