Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

MDB and Session Bean Pool - Instance or Thread?

 
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
 
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?
 
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.
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic