Bug 274 : Use "Fairness" notification on Threads waiting on DataSourcePool that is maxed out
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.6.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
14/04/2010
Updated 
14/04/2010
Type 
Bug
 
Attachments 
No attachments

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.

 
Rob 14 Apr 05:06
Thanks to Rien

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.

Rob 14 Apr 05:09
Fixed in HEAD

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.

Rob 14 Apr 05:15
So note:

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().

Rob 14 Apr 05:40
svn

947,948,949.

woResponse

Upload a file