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 8828249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:33:46+00:00 2026-06-14T07:33:46+00:00

I have a GenericKeyedObjectPool in my application. I can close it with the close

  • 0

I have a GenericKeyedObjectPool in my application.
I can close it with the close method but how should I wait for the clients to return (and the pool destroys) every borrowed object to the pool?

I need something like ExecutorService.awaitTermination.

  • 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-06-14T07:33:47+00:00Added an answer on June 14, 2026 at 7:33 am

    Create a wrapper for the GenericKeyedObjectPool which has the required awaitTermination method. You can check the close and the returnObject calls and decrement a latch if the pool is closed and every object was returned (= the total number of instances current borrowed from this pool is zero).

    public final class ListenablePool<K, V> {
    
        private final GenericKeyedObjectPool<K, V> delegate;
    
        private final CountDownLatch closeLatch = new CountDownLatch(1);
    
        private final AtomicBoolean closed = new AtomicBoolean();
    
        public ListenablePool(final KeyedPoolableObjectFactory<K, V> factory) {
            this.delegate = new GenericKeyedObjectPool<K, V>(factory);
        }
    
        public V borrowObject(final K key) throws Exception {
            return delegate.borrowObject(key);
        }
    
        public void returnObject(final K key, final V obj) throws Exception {
            try {
                delegate.returnObject(key, obj);
            } finally {
                countDownIfRequired();
            }
        }
    
        private void countDownIfRequired() {
            if (closed.get() && delegate.getNumActive() == 0) {
                closeLatch.countDown();
            }
        }
    
        public void close() throws Exception {
            try {
                delegate.close();
            } finally {
                closed.set(true);
                countDownIfRequired();
            }
        }
    
        public void awaitTermination() throws InterruptedException {
            closeLatch.await();
        }
    
        public void awaitTermination(final long timeout, final TimeUnit unit) 
                throws InterruptedException {
            closeLatch.await(timeout, unit);
        }
    
        public int getNumActive() {
            return delegate.getNumActive();
        }
    
        // other delegate methods
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have read a lot of articles, but can't make animate function to run indefinitely.
have written this little class, which generates a UUID every time an object of
Have a photography site that I want to prevent image copying from. How can
Have a look on following application http://itunes.apple.com/us/app/fatbooth/id372268904?mt=8 i think they are using the same
Have one Doubt In MVC Architecture we can able to pass data from Controller
Have searched for the answer but no joy, so here goes... I'm working on
Have converted devise new session from erb to Haml but doens't work, this is
Have searched the database but need to specifically sum(of hours flown or days off)in
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:
Have a query that should hopefully be nice and simple to answer. I have

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.