[ 
https://issues.apache.org/jira/browse/SYNAPSE-595?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Asankha C. Perera resolved SYNAPSE-595.
---------------------------------------

    Resolution: Invalid
      Assignee: Asankha C. Perera

Supun

The reason why double checked locking typically fails for the singleton pattern 
implementation is because the Java memory model allows a thread to observe a 
lazily constructed object in a partially initialized state on possibly multi 
CPU/core systems. This is well described by Joshua Bloch in Effective Java - 
item # 48. It is not the case here, and connMap is a Synchronized Map, so the 
"List connections = (List) connMap.get(key);" will *always* get the latest 
valid object.

So as far as I see, this JIRA should not be categorized as a "major" "bug" and 
thus your code patch does not "fix" anything, except for always re-entering the 
same object twice for every single connection return.

-        List connections = (List) connMap.get(key);
-        if (connections == null) {
-            synchronized(connMap) {
-                // use double locking to make sure
-                connections = (List) connMap.get(key);
-                if (connections == null) {
-                    connections = Collections.synchronizedList(new 
LinkedList());
-                    connMap.put(key, connections);
-                }
+        List connections;
+        synchronized(connMap) {            
+            connections = (List) connMap.get(key);
+            if (connections == null) {
+                connections = Collections.synchronizedList(new LinkedList());
+                connMap.put(key, connections);

Ofcourse this class could still be improved, esp with some new features of the 
JDK, but its better done as an enhancement and including other overall 
improvements.

asankha

> Possible race condition in ConnectionPool implementation of nhhtp transport
> ---------------------------------------------------------------------------
>
>                 Key: SYNAPSE-595
>                 URL: https://issues.apache.org/jira/browse/SYNAPSE-595
>             Project: Synapse
>          Issue Type: Bug
>          Components: Transports
>            Reporter: Supun Kamburugamuva
>            Assignee: Asankha C. Perera
>         Attachments: SYNAPSE-595.patch
>
>
> The nhttp transport connection pool uses double checked locking when it 
> releases a connection. But double checked locking is not a recommended 
> practice in Java and its use is avoided. Simply because it is not working. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to