In MDB deployment descriptor we define <max-beans-in-free-pool> and <initial-beans-in-free-pool> elements.
During their deployment the number of beans given in <initial-beans-in-free-pool> tag are created.
Here in example <destination-jndi-name> is jndi name for Topic destination.
Once the server is started the 20 bean instances are created. And they are ready to receive messages.
because all 20 instances of the bean have subscribed to the single Topic, all the instances should receive the message. But, this is not happening!, only one instance in the pool is receiving message.
I have tried this on Weblogic 6.1 server, and have no idea whether other Application servers allow to create such pools.
Any way, my question is,
1) All the 20 instances have same implementation of OnMessage method, then why we should create the pool? Is the any other advantages, that i am not able to think of?
2) How the server is managing to pass the message to only one instance in the pool, in-spite of the fact that the bean implements MessageListener interface?
when you set Intial Pool size to 20, that really means there are 20 MDB instances available to process the messages. So when there's a message on the topic, your App. server invokes one instance with the message. If there's a second message then it invokes another instance. This is continued until all the 20 bean instances are processing message.when the next message comes in there are no bean instances available in the pool to process it. So app. server creates a new MDB instance and delegates the message to the new bean instance. The reason of setting intial size is that bean creation is an expensive task and by having a pool of beans available for message processing you are gaining performance time for each message processing. The conecpt of "Object Pooling" existed before EJBs.If you need more details read up on that topic.
Hope this helps.
But the messages can be delivered to the single instance as well.
Do you mean that, in case of concurrent messages, when one of instance is still not finished executing onMessage method, server invokes another instance from pool to handle the message.
ONLY One instance in the pool receives a copy of A MESSAGE in the topic.The pool itself is considered as a subscriber to the topic and not each instance.And so a pool receives a copy of the message. It is upto the container to handle which instance should take care of the message.
thanks!! Sujana that helped...