• Post Reply Bookmark Topic Watch Topic
  • New Topic

Create objects in GenericObjectPool  RSS feed

 
John Joe
Ranch Hand
Posts: 436
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross post : http://stackoverflow.com/questions/43860936/create-objects-in-genericobjectpool
I'm doing research on GenericObjectPool by putting Cipher in pool so it can be reused.
 
CipherFactory
  This is how I implement ObjectPool in my Example class

PrintPool

Here comes the interesting part. When I run my application, I get this output

  
****************** After borrow ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [1]
    Idle [0]
    Waiter [0]
    Total Created [1]
    ****************** After return ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [0]
    Idle [1]
    Waiter [0]
    Total Created [1]

If I run my application 3 times without returnObject to pool
 
  ****************** After borrow ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [1]
    Idle [0]
    Waiter [0]
    Total Created [1]
   
    ****************** After return ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [1]
    Idle [0]
    Waiter [0]
    Total Created [1]
   
    ****************** After borrow ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [2]
    Idle [0]
    Waiter [0]
    Total Created [2]
   
    ****************** After return ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [2]
    Idle [0]
    Waiter [0]
    Total Created [2]
   
    ****************** After borrow ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [3]
    Idle [0]
    Waiter [0]
    Total Created [3]
   
    ****************** After return ****************
    Pool for cipher with instances DESede/CBC/NoPadding
    Active [3]
    Idle [0]
    Waiter [0]
    Total Created [3]
If I run more than 10 times, I get java.util.NoSuchElementException: Timeout waiting for idle object.
My question is how can I made the pool add the cipher object if the pool is empty ? Is it possible ? Am I on the right path ? When should I use the destroyObject method ? Thanks a lot !
 
John Joe
Ranch Hand
Posts: 436
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No one...
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please first explain why you think you need the pool in the first place. Like I told you in your last two topics, it's going to do absolutely nothing for you, because constructing the ciphers is not the expensive part, and using your own ciphers in the first place is reckless and irresponsible behavior. Unless you can explain to us very clearly why you think you need to go down this path, I don't think anybody should help you lose other people's money.
 
John Joe
Ranch Hand
Posts: 436
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing research on Pooling library GenericObjectPool to control HSM session pool. The GenericObjectPool can solve the HSM open session?
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO. Object pooling is to avoid constructing very expensive objects. Ciphers are not expensive to construct. They might be expensive to initialize, but you have to initialize them every time you use them anyway.

That's not the point though. The library you said you were using probably already has facilities to perform all this crypto for you, so using ciphers directly is DANGEROUS. It's hard to get right, evidenced by the fact that the actual way you were initializing them has huge security holes in them, such as using a fixed IV.

Read the library's manual. Use the methods and classes they provide. Don't use your own crypto. Then, you also don't need the object pool.
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you need the ciphers for? Are you encrypting anything? Why?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!