You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by ra...@apache.org on 2013/03/02 16:35:06 UTC

svn commit: r1451897 - /incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java

Author: randgalt
Date: Sat Mar  2 15:35:06 2013
New Revision: 1451897

URL: http://svn.apache.org/r1451897
Log:
ONAMI-94
Refactored the lock code a bit. No need for the extra field in LockRecord. Also, made it
so that releaseLock() doesn't need to requery the map for the lock record.

Modified:
    incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java

Modified: incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java?rev=1451897&r1=1451896&r2=1451897&view=diff
==============================================================================
--- incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java (original)
+++ incubator/onami/trunk/scopes/src/main/java/org/apache/onami/scopes/ConcurrentLazySingletonScopeImpl.java Sat Mar  2 15:35:06 2013
@@ -52,9 +52,9 @@ class ConcurrentLazySingletonScopeImpl
             {
                 if ( instance == null )
                 {
+                    final LockRecord lock = getLock( key );
                     try
                     {
-                        final Object lock = getLock( key );
                         //noinspection SynchronizationOnLocalVariableOrMethodParameter
                         synchronized ( lock )
                         {
@@ -80,7 +80,7 @@ class ConcurrentLazySingletonScopeImpl
                     }
                     finally
                     {
-                        releaseLock( key );
+                        releaseLock( lock, key );
                     }
                 }
 
@@ -104,7 +104,7 @@ class ConcurrentLazySingletonScopeImpl
     }
 
     @SuppressWarnings( "SynchronizationOnLocalVariableOrMethodParameter" )
-    private Object getLock( Key<?> key )
+    private LockRecord getLock( Key<?> key )
     {
         synchronized ( locks )
         {
@@ -115,21 +115,17 @@ class ConcurrentLazySingletonScopeImpl
                 locks.put( key, lock );
             }
             ++lock.useCount;
-            return lock.lock;
+            return lock;
         }
     }
 
-    private void releaseLock( Key<?> key )
+    private void releaseLock( LockRecord lock, Key<?> key )
     {
         synchronized ( locks )
         {
-            LockRecord lock = locks.get( key );
-            if ( lock != null )
+            if ( --lock.useCount <= 0 )
             {
-                if ( --lock.useCount <= 0 )
-                {
-                    locks.remove( key );
-                }
+                locks.remove( key );
             }
         }
     }
@@ -144,8 +140,6 @@ class ConcurrentLazySingletonScopeImpl
 =======
     private static class LockRecord
     {
-        private final Object lock = new Object();
-
         private int useCount = 0;
     }
 >>>>>>> ONAMI-93 - locks field doesn't need to be static