• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threading in ejb's

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Our application requires to start new threads through Ejb's.How can we implement threads using EJB's?
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic