I am using Spring 3.1 on standalone env.
I have scenario where I am creating programmatic prototype beans.
each bean has it’s own state.(they are stateful, having unique id and etc..)
After a bean is created I am connecting it to a topic(via DLMC pragmatically).
Each message being sent to the topic contains a specific id(one of the topic’s consumers)
Latency and throughput are very important for me.
So in case i am sending load of messages to a specific bean I am having ridiculous delay between each message since that bean is very busy and it wont be free until it finish it’s current job.
So I thought that I need to create pool of the same bean each time I first create it to avoid such situation.
Any ideas how can I achieve that? Maybe there is a high level solution for that?
I am creating those spring mdbs pragmatically this way:
java code:
MyMdb myMdb= (MyMdb) beanFactory.getBean("MyMdb", id);
and xml:
<bean id="fixSessionMDB" class="com.finbird.fixgw.core.mdb.FixSessionMDB"
scope="prototype" lazy-init="true">
<constructor-arg ref="0" />
<constructor-arg ref="0" />
</bean>
You aren’t providing too many implementation details, but have a look at the following code snippet:
This code is pretty clever. Every time you ask for
"uniqueConsumer"bean, Spring will actually return some dynamic proxy that will intercept all calls. Once you try to execute any method on that bean, Spring will take one instance from the pool (or create new one) and forward to it."maxSize"and"maxWait"parameters are self-descriptive and are used to fine-tune the pool.