Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:04:21+00:00 2026-05-24T09:04:21+00:00

How do i use the spring TaskExecutor to spawn tasks such that the outof

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:04:22+00:00Added an answer on May 24, 2026 at 9:04 am

    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

    ThreadExecutor myBean=(ThreadExecutor)SpringContext.getInstance().getBean("threadExecutor");
    

    As mentioned earlier, the SpringContext should just be a regular singleton class; where in the initialization method, you will instantiate the spring applicationcontext.

    public class SpringContext {
    
       public ClassPathXmlApplicationContext context;
    
       private static SpringContext _instance = new SpringContext();
    
       private SpringContext() {
          context = new ClassPathXmlApplicationContext(new String[]{"ThreadPoolConfig.xml"});
       }
    
       public static SpringContext getInstance() {
          return _instance;
       }
    
    
       public Object getBean(String bean) {
          Object beanObj = (context != null) ? context.getBean(bean) : null;
          return beanObj;
       }
    
    }
    

    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

    <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" scope="session">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that makes use of a Spring TaskExecutor. The task
Is it possible to use Java FutureTask with a Spring TaskExecutor to get a
I use Spring MVC [version: 2.5] and Security[version: 2.0.4]. My problem looks like that:
I am trying to use Spring and wx-xmlrpc together. The problem is that XmlRpcClient
I want to use Spring framework to create application that uses Oracle 11g to
I have web application - use Spring + Tomcat. I need debug method that
I´m trying to use spring android to parse an xml that looks like that
I have a java application that use spring with a spring.xml file in the
We use Spring + Hibernate for a Webapp. This Webapp will be deployed on
I use Spring MVC (via Spring Roo) to build a small web application for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.