vibur / vibur-object-pool

Vibur Object Pool - general-purpose concurrent Java object pool
http://www.vibur.org/vibur-object-pool/
Apache License 2.0
71 stars 16 forks source link

Closing Pool: Maximum permit count exceeded #4

Closed swimmesberger closed 7 years ago

swimmesberger commented 7 years ago

When I'm closing the pool after usage following exception is thrown:

Caused by: java.lang.Error: Maximum permit count exceeded
    at java.util.concurrent.Semaphore$Sync.tryReleaseShared(Semaphore.java:192)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1341)
    at java.util.concurrent.Semaphore.release(Semaphore.java:609)
    at org.vibur.objectpool.ConcurrentPool.terminate(ConcurrentPool.java:405)
    at org.vibur.objectpool.ConcurrentPool.close(ConcurrentPool.java:410)

Pool Creation:

new ConcurrentPool<>(new ConcurrentLinkedQueueCollection<>(), new SourceItemFactory(), 128 * 6, Integer.MAX_VALUE,
            false);
simeonmalchev commented 7 years ago

@swimmesberger, sorry for my slow reply. The pool has a limit of max number of objects set to Integer.MAX_VALUE - 4096. This is not included in the javadoc, I'll include it there in the next release which should be soon.

However, having a pool with such very big max size is probably not a good idea, think about it like this, Integer.MAX_VALUE is ~2G, if one of the objects you keep in the pool has size of ~1000 bytes, then you'll need ~2TB RAM in order to keep the pool in memory. Even if your object are ~100 bytes each, you'll still need ~200GB RAM for it. Probably, the max size of the pool shouldn't be larger then, say, 10K or 100K, presuming that these are expensive to create objects.