jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject svn commit: r792552 - in /jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp: LateralTCPCacheManager.java discovery/UDPDiscoveryReceiver.java
Date Thu, 09 Jul 2009 13:38:56 GMT
Author: asmuts
Date: Thu Jul  9 13:38:56 2009
New Revision: 792552

URL: http://svn.apache.org/viewvc?rev=792552&view=rev
Log:
Fixing potential thread safety issue on the getInstance method in the lateral tcp cache.

Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheManager.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryReceiver.java

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheManager.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheManager.java?rev=792552&r1=792551&r2=792552&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheManager.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPCacheManager.java
Thu Jul  9 13:38:56 2009
@@ -20,6 +20,7 @@
  */
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -66,7 +67,7 @@
     private static LateralCacheMonitor monitor;
 
     /** Address to instance map. */
-    protected static Map instances = new HashMap();
+    protected static Map instances = Collections.synchronizedMap( new HashMap() );
 
     /** ITCPLateralCacheAttributes */
     protected ITCPLateralCacheAttributes lca;
@@ -101,9 +102,9 @@
                                                       ICacheEventLogger cacheEventLogger,
                                                       IElementSerializer elementSerializer
)
     {
-        LateralTCPCacheManager ins = (LateralTCPCacheManager) instances.get( lca.toString()
);
         synchronized ( instances )
         {
+            LateralTCPCacheManager ins = (LateralTCPCacheManager) instances.get( lca.toString()
);
             if ( ins == null )
             {
                 log.info( "Instance for [" + lca.toString() + "] is null, creating" );
@@ -114,12 +115,13 @@
                     ins = new LateralTCPCacheManager( lca, cacheMgr, cacheEventLogger, elementSerializer
);
                     instances.put( lca.toString(), ins );
                 }
+                
+                createMonitor( ins );
             }
-            createMonitor( ins );
-        }
-        ins.clients++;
+            ins.clients++;
 
-        return ins;
+            return ins;
+        }
     }
 
     /**

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryReceiver.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryReceiver.java?rev=792552&r1=792551&r2=792552&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryReceiver.java
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryReceiver.java
Thu Jul  9 13:38:56 2009
@@ -71,7 +71,7 @@
     /** number of messages received. For debugging and testing. */
     private int cnt = 0;
 
-    /** Service to get cache names and hande request broadcasts */
+    /** Service to get cache names and handle request broadcasts */
     protected UDPDiscoveryService service = null;
 
     /** Address */



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org


Mime
View raw message