• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threading in ejb's

 
Preeti Aggarwal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our application requires to start new threads through Ejb's.How can we implement threads using EJB's?
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EJB specification explicitly forbids EJBs to create and manage threads. You should consider doing your thread processses in a servlet and invoking the beans inside those threads if possible. If this isn't a good fit, have the bean pass the work to a server task.
Think of a bean as a collection of related subroutines. You should get in, work quickly and get out. If you need to spawn a thread, you're probably intending to spend too much time inside the bean anyway.
 
Vikranth Gujjar.
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To start thread from and EJB,I think you will need to write your own ClassLoader(MyClassLoader) and use this class loader to load your thread class in the session bean, further you may need to set your own security manger class in your class Loader.

MyClassLoader.setSecurityManager(mySecurityManager).
MyClassLoader.loadClass(myThread);
myThread.start();
Vikranth
 
Ryan Fernandes
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Preeti,
If you're app needs to start a new thread in an EJB, maybe you need to revisit your system design. Tim has given some pretty good ideas that you could possibly use.

Vikram,
The EJB spec forbids doing all the things that you've mentioned.
To start thread from and EJB,I think you will need to write your own ClassLoader(MyClassLoader) and use this class loader to load your thread class in the session bean, further you may need to set your own security manger class in your class Loader.

Cheers,
Ryan
[ January 11, 2004: Message edited by: Ryan Fernandes ]
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically cases that appear to "need" threads in J2EE really just need a little asynchronous-lovin. This type of problem is handled neatly and elegantly by JMS + MDBs. You get the same type of advantages as threads and you aren't breaking spec in the process.
BTW, it is rumored that managed threading support might work its way into the next EJB Specification.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Mathews:
BTW, it is rumored that managed threading support might work its way into the next EJB Specification.
Really? Where did you hear this from? I was one of those who emailed the expert group when they solicited "feature requests" but somehow I ended up with a feeling that a thread service would not be included in 3.0.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember reading this on someone's blog at one point. However, I don't remember the exact entry and it might have even been a comment to an entry. However, it was someone that I respected and therefore held some amount of validity in my mind. However, even then it was stated as rumored so don't get your hopes up or anything. If I ever find the resource again then I will be sure to post it here.
 
Steve Wink
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JCA resources can create threads - they're in an unmanaged part of the EJB container. Maybe thats what they were referring to?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!