Currently the DataSourcePool uses synchronized for locking. This mechanism does not support "Fairness" in terms of notifying the threads waiting (for busy connections to be returned).
That is, the order in which threads where queued waiting for a connection to be returned is not the same order they are notified.
To get FIFO ordering for waiting threads we need to use a ReentrantLock with 'fair' = true.
Thanks to Rien for identifying this issue and suggesting a patch for the fix.
On review though I though it better to rather than mix the synchronized blocks and ReentrantLock lock ... I'd refactor to use a single ReentrantLock exclusively.
So, in fixing this issue there is really a significant refactor of DataSourcePool.
I have committed the fix into HEAD.
Note that to confirm the fairness behaviour I added in some code to effectively log the events (wait,notify,obtain) and confirm they occur in a consistent order.
The test TestDataSourceMax used these bit's of code.
For production code I will remove the code that logged the events.
I have removed some of the code (but it was put into svn) that was used to confirm the order that threads when into wait, notify and obtain ...
This was in PooledConnectionQueue._getPooledConnectionWaitLoop().
947,948,949.