critical path in lookup of DBPortPool #67

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@gabrielenizzoli

critical path in lookup of DBPortPool: if 2 threads pass by and find no
DBPortPool for the same addr, then 2 DBPortPool objects will be created
and returned, but only one of them is actually stored in the _pool map
(side effect is that on close() only one DBPortPool will be closed);
note that this patch will make the _pool object a non synchronized map
to avoid double synchronization

@gabrielenizzoli gabrielenizzoli critical path in lookup of DBPortPool: if 2 threads pass by and find no
DBPortPool for the same addr, then 2 DBPortPool objects will be created
and returned, but only one of them is actually stored in the _pool map
(side effect is that on close() only one DBPortPool will be closed);
note that this patch will make the _pool object a non synchronized map
to avoid double synchronization
7fdbf94
@jyemin jyemin was assigned Sep 19, 2012
@trishagee

Apologies for the delay in response. I agree that your code would definitely work, but the race condition you talk about is not actually a problem - the existing second check inside the synchonized block will stop the second thread from creating a new pool. That first check is an optimisation to allow a fast, non-synchronized access to the collection to return quickly in the case that a pool currently exists.

I agree that this code is not very readable and can certainly be simplified, and my colleagues and I are in the process of doing just that - the 3.0 branch has a much cleaner architecture for managing connections, and simpler code too. Feel free to take a look.

@trishagee trishagee closed this Jul 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment