jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1461442 - /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakMongoMKRepositoryStub.java
Date Wed, 27 Mar 2013 08:29:30 GMT
Author: mreutegg
Date: Wed Mar 27 08:29:30 2013
New Revision: 1461442

URL: http://svn.apache.org/r1461442
Log:
OAK-619 Lock-free MongoMK implementation
- avoid strong references from shutdown hook to resources (allows to free resources earlier
if possible)

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakMongoMKRepositoryStub.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakMongoMKRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakMongoMKRepositoryStub.java?rev=1461442&r1=1461441&r2=1461442&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakMongoMKRepositoryStub.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakMongoMKRepositoryStub.java
Wed Mar 27 08:29:30 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import java.lang.ref.WeakReference;
 import java.security.Principal;
 import java.util.Properties;
 import java.util.concurrent.Executors;
@@ -78,12 +79,25 @@ public class OakMongoMKRepositoryStub ex
                 session.logout();
             }
         }
-        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
-            @Override
-            public void run() {
+        Runtime.getRuntime().addShutdownHook(
+                new Thread(new ShutdownHook(connection)));
+    }
+
+    private static class ShutdownHook implements Runnable {
+
+        private final WeakReference<MongoConnection> reference;
+
+        public ShutdownHook(MongoConnection connection) {
+            this.reference = new WeakReference<MongoConnection>(connection);
+        }
+
+        @Override
+        public void run() {
+            MongoConnection connection = reference.get();
+            if (connection != null) {
                 connection.close();
             }
-        }));
+        }
     }
 
     public static boolean isMongoDBAvailable() {



Mime
View raw message