geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1613224 - /geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AsynchronousInheritanceAnnotationFinder.java
Date Thu, 24 Jul 2014 18:07:01 GMT
Author: rmannibucau
Date: Thu Jul 24 18:07:00 2014
New Revision: 1613224

URL: http://svn.apache.org/r1613224
Log:
XBEAN-270 no real way to auto destroy the scanner thread so adding a manual method

Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AsynchronousInheritanceAnnotationFinder.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AsynchronousInheritanceAnnotationFinder.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AsynchronousInheritanceAnnotationFinder.java?rev=1613224&r1=1613223&r2=1613224&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AsynchronousInheritanceAnnotationFinder.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/AsynchronousInheritanceAnnotationFinder.java
Thu Jul 24 18:07:00 2014
@@ -20,8 +20,6 @@ package org.apache.xbean.finder;
 
 import org.apache.xbean.finder.archive.Archive;
 
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
@@ -31,10 +29,9 @@ import java.util.concurrent.atomic.Atomi
 
 // designed to trigger asynchronism from a single thread
 public class AsynchronousInheritanceAnnotationFinder extends AnnotationFinder {
-    private ExecutorService executor = null;
-    private CountDownLatch subclassesLatch = null;
-    private CountDownLatch implementationsLatch = null;
-    private Collection<CountDownLatch> latchToWait = new ArrayList<CountDownLatch>(2);
// ensure we cleanup scanning threads
+    private volatile ExecutorService executor = null;
+    private volatile CountDownLatch subclassesLatch = null;
+    private volatile CountDownLatch implementationsLatch = null;
 
     public AsynchronousInheritanceAnnotationFinder(final Archive archive, final boolean checkRuntimeAnnotation)
{
         super(archive, checkRuntimeAnnotation);
@@ -44,6 +41,10 @@ public class AsynchronousInheritanceAnno
         super(archive);
     }
 
+    public void destroy() {
+        executor.shutdownNow();
+    }
+
     @Override // should be called from main thread
     public AnnotationFinder enableFindImplementations() {
         if (implementationsLatch == null) {
@@ -61,7 +62,6 @@ public class AsynchronousInheritanceAnno
                     }
                 }
             });
-            latchToWait.add(implementationsLatch);
         }
         return this;
     }
@@ -76,7 +76,6 @@ public class AsynchronousInheritanceAnno
                     subclassesLatch.countDown();
                 }
             });
-            latchToWait.add(subclassesLatch);
         }
         return this;
     }
@@ -107,15 +106,12 @@ public class AsynchronousInheritanceAnno
     }
 
     private void join(final CountDownLatch latch) {
-        if (latchToWait.remove(latch)) {
+        if (latch != null) {
             try {
                 latch.await();
             } catch (final InterruptedException e) {
                 // no-op
             }
-            if (latchToWait.isEmpty()) {
-                executor.shutdown();
-            }
         }
     }
 



Mime
View raw message