How do i use the spring TaskExecutor to spawn tasks such that the outof memory exception are not thrown.
Current task pool configuration:
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="56" />
<property name="maxPoolSize" value="112" />
<property name="queueCapacity" value="100" />
</bean>
<bean id="threadExecutor" class="com.content.ThreadHandler.ThreadExecutor">
<constructor-arg ref="taskExecutor" />
</bean>
</beans>
and i am using the bean in my request handler by using the load bean as:
ApplicationContext context=new ClassPathXmlApplicationContext(new String[]{"ThreadPoolConfig.xml"});
BeanFactory factory=context;
ThreadExecutor myBean=(ThreadExecutor)factory.getBean("threadExecutor");
and then i use the taskexecutor as mybean.execute(task);
Does this configuration create a new pool for each request?
SUGGESTION 1
You shouldn’t be instantiating the Spring application context for each request. You should have a singleton class named SpringContext or something like that and that should instantiate the Spring application context only once. So your client code should just be
As mentioned earlier, the SpringContext should just be a regular singleton class; where in the initialization method, you will instantiate the spring applicationcontext.
SUGGESTION 2
In case this doesn’t work, then you should look into the following :
The spring bean element has a scope attribute. Two of the values you can specify there are request and session, corresponding to HTTPRequest and HTTPSession. Try using one of them in your case.
http://static.springsource.org/spring/docs/3.0.x/reference/beans.html#beans-factory-scopes
So your bean definition should look something like