This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
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
posted
0
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: 912
posted
0
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
Ross Crockett
Greenhorn
Joined: Aug 25, 2009
Posts: 28
posted
0
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
posted
0
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
Greenhorn
Joined: Aug 25, 2009
Posts: 28
posted
0
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: MDB and Session Bean Pool - Instance or Thread?