aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes MDB and Session Bean Pool - Instance or Thread? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "MDB and Session Bean Pool - Instance or Thread?" Watch "MDB and Session Bean Pool - Instance or Thread?" New topic
Author

MDB and Session Bean Pool - Instance or Thread?

Ross Crockett
Ranch Hand

Joined: Aug 25, 2009
Posts: 30
Hello Ranchers

I've got a question regarding the implementation of MDB and Session Bean Pooling. I read in a lot of places (ejb-spec included) that when needed, the container creates "a new instance" of the bean for the pool when needed. In other places I read about how when a request comes in for a Session Bean or MDB a "new thread" is assigned from the pool to handle it.

So is the pool made up of:

1. A whole bunch of actual instances of Objects? e.g. container is going "new MyMDB()" a whole bunch of times and pooling them (up to your max pool size).

or

2. Creating one instance to start, and then creating a thread of that instance to handle the request? i.e. similar to how servlets work, where there is one instance of the actual Object but a new thread is made to handle the request.

I can't seem to find a definitive answer anywhere, and it seems the terminology between a thread and an instance is being used interchangeably (which is wrong). I'm thinking that number 1. above is how it's working, but if there is a reason why the word 'thread' is used I would like to know why. Especially if there is any difference between how Session Bean and MDB pooling is implemented.

Cheers,
Ross
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
It's instance pulling, and a thread uses an instance. I think it's quite straightforward. What is the point of many instances if there is only one thread working on one instance at a time?


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi

IMHO the server uses a thread pool and a MDB pool also. The threads from pool never ends - after they end the assigned task they go and wait (until a new task is coming). The container assign threads with mdb objects (as Kengkaj suggest).

Regards,
Mihai


SCJP, SCJD, SCWCD, OCPJBCD
Ross Crockett
Ranch Hand

Joined: Aug 25, 2009
Posts: 30
Thanks for the reply.

So one instance, and many threads of that instance like I thought it might be.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Ross Crockett wrote:Thanks for the reply.

So one instance, and many threads of that instance like I thought it might be.

One instance and one thread. Many instances and many threads. One thread uses one instance.
Ross Crockett
Ranch Hand

Joined: Aug 25, 2009
Posts: 30
Ah ok, that makes sense. I think the best way to put in that case would be:

One thread per instance.

With there being more often than not, multiple instances in the pool.
 
 
subject: MDB and Session Bean Pool - Instance or Thread?