I'm sure the correct answer to this depends on the type of pooled objects and the workload, so I'll detail my implementation a bit:
I have an ObjectPool used to pool long-running command-line processes. These processes communicate via stdin/stdout, and perform file/network operations. Many tasks complete much faster than others and may return processes to the pool quickly. All access to the pool must be thread-safe.
My question is, am I better off managing the pool with a LIFO/Stack, or a FIFO/ConcurrentLinkedQueue? My reasoning on both sides:
- A stack keeps "hot" objects in play, where resources may remain cached/etc. for longer.
- A FIFO balances calls more evenly between the processes, with each doing less work. Thanks!