On 11/21/06, Tom <[EMAIL PROTECTED]> wrote:
I have a pool of 4 services. Every time a task needs to be performed, I borrow one service from the pool, have it execute the task, and return it. This seems to me as being a sensible pool.
Okay, I think I now have an idea of what you are trying to achieve. In terms of Pool you would want a pool with a maxActive setting set to 4 and make sure there is no minIdle or idle object evictor or anything else that could cause the pool to loose poolable objects. But, I'm not sure a Pool is the best fit for what you want. If you aren't strongly attached to a Stack ordering (LIFO) then I'd suggest a BlockingQueue (FIFO) from util.concurrent. If you cannot use Java 1.5 then I'm pretty sure backport-util-concurrent will be able to help you out. Simply stuff a ArrayBlockingQueue with your 4 service instances and then take() and put() services. That will probably be faster than the existing pools too. If you need to activate/passivate services you may want to write a wrapper for this queue. It wouldn't be hard to make that wrapper implement ObjectPool either. http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html http://dcl.mathcs.emory.edu/util/backport-util-concurrent/
Since using a factory is preferred, I have a collection based factory in which makeObject removes one from the collection and hands it over to the pool. There is no lazy creation here. When requesting a 5th service in this scenario, Apache's Stack makes the CPU go to 100%
I agree there shouldn't be an infinite loop if it can be avoided. I'll make sure this gets fixed for the next release.
I have tried to clearly explain why I feel there is a conceptual bug (I feel an implementation should not be able to go into an endless loop this easily). I understand that the currently implementation is perfectly suited for infinite (lazily create) pools. I have also shown IMHO that when the implementation is used for non infinite pools (and they do exist), they are buggy.
Pool assumes that poolable objects could become invalid over time. If makeObject cannot create objects as needed, the the pool would run dry.
So, there is no pun intended here, and the current implementation has worked for our infinite pools perfectly for years. But I need an finite pool and have implemented both a round robin and a stack that works both in the lazy create and in the finite mode.
If you want to share those implementations, create an issue and attach the sources. I cannot promise it will be included in the official package but we can point others there if they have similar needs.
It is up to the Apache developers to check and see if there is merit to my point and if you are interested in this alternative and would like to take a peek at the source. Or not. For me, my problem is solved.
It's non-trivial to accept code that wasn't written by Apache members because of licensing issues but I'm happy to look and learn from a good idea when I see one. -- Sandy McArthur "He who dares not offend cannot be honest." - Thomas Paine --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
