polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [12/19] zest-java git commit: Revert "locking: remove workaround for old HotSpot bug fixed in h17(b06)"
Date Sat, 24 Dec 2016 10:29:24 GMT
Revert "locking: remove workaround for old HotSpot bug fixed in h17(b06)"

This reverts commit 3565bcba7bcf2e4ad62a96c8daff72178c3e9d1a.


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/42e2b7cc
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/42e2b7cc
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/42e2b7cc

Branch: refs/heads/develop
Commit: 42e2b7cc9f0063c6971a68c369170f6ba5e7130b
Parents: 90bc41c
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sun Dec 18 13:17:27 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sun Dec 18 13:17:27 2016 +0100

----------------------------------------------------------------------
 .../library/locking/WriteLockConcern.java       | 32 ++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/42e2b7cc/libraries/locking/src/main/java/org/apache/polygene/library/locking/WriteLockConcern.java
----------------------------------------------------------------------
diff --git a/libraries/locking/src/main/java/org/apache/polygene/library/locking/WriteLockConcern.java
b/libraries/locking/src/main/java/org/apache/polygene/library/locking/WriteLockConcern.java
index c9b632b..53fd4e6 100644
--- a/libraries/locking/src/main/java/org/apache/polygene/library/locking/WriteLockConcern.java
+++ b/libraries/locking/src/main/java/org/apache/polygene/library/locking/WriteLockConcern.java
@@ -21,6 +21,7 @@ package org.apache.polygene.library.locking;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import org.apache.polygene.api.common.AppliesTo;
@@ -31,17 +32,20 @@ import org.apache.polygene.api.injection.scope.This;
  * Applies write-lock to Composite
  */
 @AppliesTo( WriteLock.class )
-public class WriteLockConcern extends ConcernOf<InvocationHandler>
+public class WriteLockConcern
+    extends ConcernOf<InvocationHandler>
     implements InvocationHandler
 {
+    private
     @This
-    private ReadWriteLock lock;
+    ReadWriteLock lock;
 
     @Override
     public Object invoke( Object o, Method method, Object[] objects )
         throws Throwable
     {
         Lock writeLock = lock.writeLock();
+        lock(writeLock);
         try
         {
             return next.invoke( o, method, objects );
@@ -51,4 +55,28 @@ public class WriteLockConcern extends ConcernOf<InvocationHandler>
             writeLock.unlock();
         }
     }
+
+    /**
+     * Fix for this bug:
+     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6822370
+     */
+    protected void lock(Lock lock)
+    {
+        while(true)
+        {
+            try
+            {
+                //noinspection StatementWithEmptyBody
+                while( !lock.tryLock( 1000, TimeUnit.MILLISECONDS ) )
+                {
+                    // On timeout, try again
+                }
+                return; // Finally got a lock
+            }
+            catch( InterruptedException e )
+            {
+                // Try again
+            }
+        }
+    }
 }
\ No newline at end of file


Mime
View raw message