• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threading works! on session bean  RSS feed

 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
EJB is NOT supposed to support threading. I am not sure how this is to be enforced. At any rate, I created a session bean that extends Thread. In the run() method, I put a print statement. So when the bean was invoked, the app server did not throw any errors, and it printed out the statement I had placed in the run() method.

Isn't this VERY wrong? Or am I automatically expected to disallow multi-threading?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB is NOT supposed to support threading


EJBs are just Java classes, and as such they support threading. It's more like YOU -as the developer- are not supposed to use threading in EJBs, just like you're not supposed to use file I/O.
[ April 08, 2007: Message edited by: Ulf Dittmer ]
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nupur,

what you try to do is against the EJB Spec . It's the EJB Container's business to concern about threading. I wonder what kind of threading you need on the app server side.

This picture looks different when you are doing GUI stuff. But on the server side there is nothing for you concerning threading .

Regards,
Darya
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it printed out the statement I had placed in the run() method.

Is it so, that you did not call run method and still it got executed?
When the ejb specs say that EJBs should not use multithreading, it means that one should not spawn new threads inside an EJB's code. This essentially means that a thread(spawned by the bean) should not be executing even after a business method of an EJB returns.
 
vu lee
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure whether EJB container implementing any logic to restrict multithreadings. IMO, the container may not guarantee the contract when EJB component spawned threads.

I once saw one of my coworker created multiple threads within a SLSB to handle different rules. The SLSB was hosted by Jboss. I thought he better not do that, but his codes ran fine. :roll:
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO, the container may not guarantee the contract when EJB component spawned threads.

Exactly, this is the reason why the ejb specs disallow threading in the EJBs.
This link details some reasons for restrictions on EJBs
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, Thanks all, but I have read that one of the functions of the J2EE container is to take care of threading issues. So it still does nothing, and we have to ensure that the bean is not spawning threads, or reading and writing files?
What about transaction management?Again, the container is supposed to ensure data integrity for db transactions. So does that mean we have to implement it ourselves? The container actually does nothing?

Thanks a lot, peeps.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!