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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:18:57+00:00 2026-06-15T19:18:57+00:00

I am trying to use apache commons pool to create a pool of ‘objects’.

  • 0

I am trying to use apache commons pool to create a pool of ‘objects’. Since I already have an object factory which takes a string type argument and create a right type of object I want to use this factory.

But the problem is that none of the signatures of generic pool object allow me to pass a factory which takes arguments.

//This is a wrapper class that holds an Object pool
Class INService {

    private ObjectPool<INConnection> pool_ = null;

    /**
     * Constructs an instance of INService, given a pool size 
     * and a class which implements INHandler interface.
     * @param poolSize - size of the service pool 
     * @param c - the class which handles the INHandler service interface.
     */
    public INService(int poolSize, String objectType) {

        pool_ = new GenericObjectPool<INConnection>(factory, Objecttype); // won't compile.
    }
    ...
}

The PoolableObjectfactory interface defines methods like makeObject, destroyObject, validateObject, activateObject and passivateObject. But no makeObject() method which takes parameters.

It seems that the only way I can do this is to write multiple factory classes for each type of object and write an if-else stuff, like:

    public INService(int poolSize, String objectType) {

        if (objectType.equals("scap")
            pool_ = new GenericObjectPool<INConnection>(scapFactory);
        else if (objectType.equals("ucip")
            pool_ = new GenericObjectPool<INConnection>(ucipFactory);
        ...
    }

Or, is there any elegant way, instead of duplicating/creating several factory classes just for this sake?

  • 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-15T19:18:58+00:00Added an answer on June 15, 2026 at 7:18 pm

    You should read up on the KeyedObjectPool<K,V> interface which can also be found in commons-pool.

    From its javadoc:

    A keyed pool pools instances of multiple types. Each type may be accessed using an arbitrary key.
    

    You could then implement a KeyedPoolableObjectFactory<K,V> to make instances based on the key parameter, it has the makeObject(K key) function you are looking for.

    PS: It appears you haven’t marked any answers to your questions as “accepted”, you might want to work on that.

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

Sidebar

Related Questions

I'm trying to create a vector object by importing org.apache.commons.math3.geometry.Vector . Which confuses me
I have a program that is trying to use the org.apache.commons.io.FileUtils static method readFileToString()
I am trying to use org.apache.commons.collections.CollectionUtils in android with following code import java.util.ArrayList; import
I am trying to use GLSMultipleLinearRegression (from apache commons-math package) for multiple linear regression.
I am trying to figure out how to use Apache Commons IO DirectoryWalker .
I'm trying to use VFS S3 a plugin for the Apache Commons VFS for
I am trying to download an image from URL. I use the Apache Commons
I'm trying to use Apache Commons Net for FTP file transfers. Problem is files
We're trying to use Apache Commons VFS to access something over SFTP. It claims
Ok so I'm trying to use Apache Commons Math library to compute a double

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.