Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB and other Java EE Technologies and the fly likes Threads in EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Threads in EJB" Watch "Threads in EJB" New topic
Author

Threads in EJB

Raj Jindal
Ranch Hand

Joined: Jan 17, 2003
Posts: 50
can we implement threads in ejb bean.
If yes, what is the benefit of this.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
No. Managing threads is strictly disallowed by the EJB Specification.
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
and the container is supposed to take care of transaction integrity issues(basically they are removing the comlexity that comes with thread usage from a enterprise system developer's brain).
Dan.


Kishore
SCJP, blog
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by raj jindal:
can we implement threads in ejb bean.

Not in the "(new Thread(someRunnable)).start()" sense. However, if you need asynchronous processing, you can use message-driven beans. When you make a method call on a session bean, the caller blocks until the bean's method returns. With an MDB, you push a message onto a queue and immediately regain control (the caller). The container then gives the message to an MDB to process out-of-band of the thread the created the message.
For example, say that in your order processing system the last step is to validate, print, and electronically send the order somewhere. If you don't want to process orders serially (one at a time), you could post JMS messages to an order-processing queue. If you deploy five order-processing MDBs, then five orders will be processed concurrently. The process that starts the process would create and post the messages and then immediately return without waiting for the orders to be processed.
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi Raj,
Ur other post "I/O operation in EJB "
R u planning to prove that "EJB Development" can be overridden ie ur planning to do something that EJB specs says it should not do.
If yes, let us all know what u've done in EJB by
1. Creating a thread.
2. Doing IO operations.
3. Loading Native programs
etc
etc
Seetesh
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Originally posted by David Harkness:
If you deploy five order-processing MDBs, then five orders will be processed concurrently.

David,
I understand that you meant this as just an example to clarify the above poster's question.
But I haven't worked much with the EJB Servers, hence would like to know if it is really possible to restrict the number of MDBs or SLSBs that could be created by the Container?...Is that vendor specific and if so, which all app servers support this feature?
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Originally posted by Vish Kumar:
But I haven't worked much with the EJB Servers, hence would like to know if it is really possible to restrict the number of MDBs or SLSBs that could be created by the Container?...Is that vendor specific and if so, which all app servers support this feature?

Yes, but restricting the size of the pool is done in a vendor specific way. Every Application Server that I have used has provided this feature.
Jason Stull
Ranch Hand

Joined: Feb 02, 2004
Posts: 47
We use JBoss and according to one of the JBoss developers the container will spin off a seperate process for each queue posting. If you want to post six times consecutively from a Session Bean to a particular queue with corresponding mdb listening , then six processes will run concurrently. I was also told that this may vary accross container implementations.


"I believe in coyotes and time as an abstract Explain the change the difference between What you want and what you need there's the key"
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Threads in EJB
 
Similar Threads
Can We Apply User Defined Threads in EJB?
threading in ejb??
can thread play in distributed environment
Can we use user defined threads in EJB. If not then why?
Throttling