Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MDB and Session Bean Pool - Instance or Thread?

 
Ross Crockett
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ross Crockett
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

So one instance, and many threads of that instance like I thought it might be.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic