0

I am trying to add objects to object pool. I am using apache commons pool for this.

My code as is as follows:

public ObjectPool<OAuthConsumer> consumerPool;

public ObjectPool<OAuthConsumer> consumerPool;


public void buildConsumerPool(){

    //setting the config path
    PropertyHandler.setConfigPath("/twitter.properties");

    //fetching required tokens for all apps
    String consumerKeySet = PropertyHandler.getProperty("consumerKey");
    String consumerSecretSet = PropertyHandler.getProperty("consumerSecret");
    String accessTokenSet = PropertyHandler.getProperty("accessToken");
    String tokenSecretSet = PropertyHandler.getProperty("tokenSecret");

    String[] splitconsumerKeys = consumerKeySet.split(",");
    String[] splitconsumerSecret = consumerSecretSet.split(".");
    String[] splitaccessToken = accessTokenSet.split(",");
    String[] splittokenSecret = tokenSecretSet.split(".");

    //creating consumer objects for each app
    for (int numberOfAccounts = 0; numberOfAccounts < splitconsumerKeys.length; numberOfAccounts++) {

            String consumerKey = splitconsumerKeys[numberOfAccounts];
            String consumerSecret = splitconsumerSecret[numberOfAccounts];
            String accessToken = splitaccessToken[numberOfAccounts];
            String tokenSecret = splittokenSecret[numberOfAccounts];
            OAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
            consumer.setTokenWithSecret(accessToken, tokenSecret);

    }

Now i want to add consumer objects to the pool i created before. How do i do that?

2
  • consumerPool.addObject(consume) doesnt do the trick? Commented Feb 23, 2014 at 7:55
  • addObject doesnt take a parameter. I checked. Commented Feb 23, 2014 at 7:57

1 Answer 1

1

Check this link for more info on using pools GenericObjectPool

Another post which might help is this

You need to associate a factory with your ObjectPool to create objects. Hope this helps.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you , i wish it was more straighforward than this. addObject should have done the job. Trying to associate a factory now.
@NischalHp please consider accepting the answer if you think this helped.
Done , it actually helped but i ended up not using it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.