You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/08/02 17:03:39 UTC

git commit: fix concurrency issues in StringLocks by temporarily disabling garbage collection of locks

Updated Branches:
  refs/heads/develop d551ec077 -> 44c5d3bae


fix concurrency issues in StringLocks by temporarily disabling garbage collection of locks


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/44c5d3ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/44c5d3ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/44c5d3ba

Branch: refs/heads/develop
Commit: 44c5d3bae462619461dc78c88cdb30d5d760a682
Parents: d551ec0
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Aug 2 17:03:33 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Aug 2 17:03:33 2013 +0200

----------------------------------------------------------------------
 .../marmotta/commons/locking/StringLocks.java   | 29 +++++++++-----------
 .../kiwi/test/PostgreSQLConcurrencyTest.java    |  4 +--
 2 files changed, 15 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/44c5d3ba/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/locking/StringLocks.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/locking/StringLocks.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/locking/StringLocks.java
index c665e63..3b24aef 100644
--- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/locking/StringLocks.java
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/locking/StringLocks.java
@@ -33,36 +33,33 @@ public class StringLocks {
 
     private LoadingCache<String,Monitor> stringLocks;
 
-    // keeps strong references for locks that are in use
-    private HashSet<Monitor> activeLocks;
-
     public StringLocks() {
-        stringLocks = CacheBuilder.newBuilder().weakValues().build(new LockCacheLoader());
-        activeLocks = new HashSet<>();
+        stringLocks = CacheBuilder.newBuilder().build(new LockCacheLoader());
     }
 
 
     public void lock(String name) {
-        Monitor lock = stringLocks.getUnchecked(name);
+        Monitor lock;
+        synchronized (stringLocks) {
+            lock = stringLocks.getUnchecked(name);
+        }
         lock.enter();
-        activeLocks.add(lock);
     }
 
     public void unlock(String name) {
-        Monitor lock = stringLocks.getUnchecked(name);
-        lock.leave();
-        if(lock.getOccupiedDepth() == 0) {
-            activeLocks.remove(lock);
+        Monitor lock;
+        synchronized (stringLocks) {
+            lock = stringLocks.getUnchecked(name);
         }
+        lock.leave();
     }
 
     public boolean tryLock(String name) {
-        Monitor lock = stringLocks.getUnchecked(name);
-        boolean result = lock.tryEnter();
-        if(result) {
-            activeLocks.add(lock);
+        Monitor lock;
+        synchronized (stringLocks) {
+            lock = stringLocks.getUnchecked(name);
         }
-        return result;
+        return lock.tryEnter();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/44c5d3ba/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
index b3c97c2..70eedf2 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PostgreSQLConcurrencyTest.java
@@ -138,8 +138,8 @@ public class PostgreSQLConcurrencyTest {
     long tripleCount = 0;
 
     @Test
-    @Concurrent(count = 10)
-    @Repeating(repetition = 10)
+    @Concurrent(count = 15)
+    @Repeating(repetition = 10000)
     public void testConcurrency() throws Exception {
         runs++;