• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads and EJB  RSS feed

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been thinking for the past few hours about how to thread a certain business method of one of my EJB's. And only after spending that time did a silent warning go off in my head. So off I went to page 9 of the J2EE tutorial, where it says:
Enterprise beans make use of the services provided by the EJB Container...to avoid conflicts...(EJB) are restricted from performing certain operations:
*Managing or synchronizing threads
Well that sucks! But I suppose it makes other things simpler.

My idea was this: I have an EJB that takes certain data and emails it to someone. But this emailing can sometimes take some time. (JavaMail resolves the @my.domain.com before sending). And the reason that the time is somewhat unacceptable, is that the front end is a JSP. So my webpage just sits there and hangs, until finally the Transport.send(msg) returns. So I wanted to thread this out.

Does anyone have any ideas how else I can implement something like this? (is there a way to make Transport.send() non-blocking?)

Inside the EJB can I implement an inner class which extends Thread? I wouldn't be asking the bean to manage anything. Or is it implicit when you say "myInnerMailerClass.start()"?

Did that make sense?
[This message has been edited by Mike Curwen (edited May 09, 2001).]
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the non-blocking behaviour you're mentioning check out JMS.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I knew about JMS, but I was hoping to avoid it. As I understand, message driven beans are not part of the ejb spec i'm working with (1.1).

But here is a simpler solution which someone at work thought of. (I always miss the simple ones!). My web app has a servlet acting as a switch. ie: There is no URL that accesses a JSP page directly. Everything goes through a servlet with a page parameter. So my "Send Mail" logic in the servlet finds the EJB, performs the "send" business method on that EJB and then gets a request dispatcher and forwards to the "sent.jsp".

Well duh... why not use response.sendRedirect("sent.jsp") at some point prior to all the EJB stuff? . Now the webpage doesn't hang, and my EJB quietly works away in the background to send the email.

Thanks for the JMS tip, but I like this solution because it requires a lot less work on my part! LOL
[This message has been edited by Mike Curwen (edited May 10, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!