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

  • Home
  • SEARCH
  • 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 3332280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:40:17+00:00 2026-05-17T23:40:17+00:00

I have a Spring CommonsPoolTargetSource defined for a bean. I’m trying to understand how

  • 0

I have a Spring CommonsPoolTargetSource defined for a bean. I’m trying to understand how pooling works, and when an object is returned the the pool.

Specifically, if I have a worker, which takes a pooled object and invokes two methods on it, as follows:

public class MyWorker {
    @Resource
    Foo pooledFoo;

    void doWork()
    {
        pooledFoo.doStepA();
        pooledFoo.doStepB();
    }
}

From what I can see in the tests I’ve run, pooledFoo is not actually an instance of Foo, but a proxy provided by the Pool. The flow in the above would be:

  • Invoking doStepA() on foo retrieves a value from the pool (blocking the thread if one is not available),
  • doStepA is executed on the pooledFoo
  • when doStepA completed, pooledFoo instance is returned to the pool
  • control returns to the doWork method, and the method continues

If this is correct (please tell me if it’s not), is it fair to assume that the pooledFoo returned from the pool when doStepB() is invoked, will not be the same instance that was returned for doStepA()?

  • 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-17T23:40:18+00:00Added an answer on May 17, 2026 at 11:40 pm

    Your description of the flow is correct – the object will be borrowed from the pool before each invocation, and returned to it afterwards.

    However, you next assumption is wrong – it’s entirely possible that stepB will be invoked against the same pooled instance as stepA. It depends on the “churn” on the pool – how often are objects borrowed and returned by different threads. Under low load, the same object might be reused.

    So there’s no guarantee of anything here. With pooled objects, you generally want to leave the pooled object in a state where it is fit to be used by the next borrower, regardless of whether not the borrower is the same thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Spring proxies set up: <bean id=simpleBean class=org.springframework.aop.framework.ProxyFactoryBean> <property name=target> <ref local=simpleBeanTarget/>
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
Assume that we have Spring bean UserController with singleton scope. All my further reasoning
Is it possible to have Spring inject the JPA entityManager object into my DAO
I have a Spring Interceptor which attempts to add an HTTP header in the
Does Java and/or Spring have the concept of properties? I have bunch of domain
We have started using Spring framework in my project. After becoming acquainted with the
We have started to use spring aop for cross cutting aspects of our application
I have a JSP that is using Spring:form tags to bind controls to a
We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests

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.