• Post Reply Bookmark Topic Watch Topic
  • New Topic

threads in EJB  RSS feed

 
Andron Dre
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, easy questions for pros
what about creating your thread inside EJB container ?
please mention pros and cons,
comparison to JMS
thx
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(1) Don't create threads inside an EJB method. This is a VERY BAD idea. First of all, the spec explicitly says that you shouldn't do it, and secondly, if you do, then the newly created threads will not be enlisted in the EJB transaction of the thread that started it. It's an EXTREMELY easy way to confuse your Transaction Manager.
(2) Starting threads elsewhere inside the container (for instance, in a vendor-provided startup class) is a fairly common occurance. Since the thread isn't running as part of the EJB programming model, it's usually pretty innocuous.
Now, exactly what in JMS did you want to compare this with? Was it the asynchrounous message receipt part (MDB's) that you wanted a comparison to? If so, the JMS wins over doing this sort of annoying low-level programming hands down. You don't need to reinvent middleware yet again...
Kyle
 
Matjaz Juric
Author
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJBs are not allowed to start threads. This is what EJB spec says (24.1.2):
"The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt
to start, stop, suspend, or resume a thread; or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups."
Cheers,
Matjaz
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!