commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r264816 - /jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/SingletonProvider.java
Date Tue, 30 Aug 2005 17:17:31 GMT
Author: jcarman
Date: Tue Aug 30 10:17:23 2005
New Revision: 264816

URL: http://svn.apache.org/viewcvs?rev=264816&view=rev
Log:
Now using a simple synchronized block rather than a read/write lock.

Modified:
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/SingletonProvider.java

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/SingletonProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/SingletonProvider.java?rev=264816&r1=264815&r2=264816&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/SingletonProvider.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/SingletonProvider.java
Tue Aug 30 10:17:23 2005
@@ -18,8 +18,6 @@
 
 import org.apache.commons.proxy.DelegateProvider;
 
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
 /**
  * Wraps another delegate provider, making sure to only call it once, returning the value
returned from the wrapped
  * provider on all subsequent invocations.
@@ -30,7 +28,6 @@
 public class SingletonProvider extends ProviderDecorator
 {
     private Object instance;
-    private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
 
     public SingletonProvider( DelegateProvider inner )
     {
@@ -39,20 +36,14 @@
 
     public Object getDelegate()
     {
-        rwl.readLock().lock();
-        if( instance == null )
+        synchronized( this )
         {
-            rwl.readLock().unlock();
-            rwl.writeLock().lock();
             if( instance == null )
             {
                 instance = super.getDelegate();
                 inner = null; // Garbage collection
             }
-            rwl.readLock().lock();
-            rwl.writeLock().unlock();
         }
-        rwl.readLock().unlock();
         return instance;
     }
 }



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


Mime
View raw message