Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Threading works! on session bean

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic