You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2009/08/04 23:22:42 UTC

svn commit: r800982 - /incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java

Author: cwiklik
Date: Tue Aug  4 21:22:41 2009
New Revision: 800982

URL: http://svn.apache.org/viewvc?rev=800982&view=rev
Log:
UIMA-1439 Spin a thread to wait for threads in the taskExecutor  

Modified:
    incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java

Modified: incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java?rev=800982&r1=800981&r2=800982&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java (original)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java Tue Aug  4 21:22:41 2009
@@ -29,6 +29,7 @@
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.uima.aae.UIDGenerator;
 import org.apache.uima.aae.UimaAsContext;
 import org.apache.uima.aae.UimaAsThreadFactory;
 import org.apache.uima.aae.controller.AggregateAnalysisEngineController;
@@ -73,8 +74,9 @@
 
   public VmTransport(UimaAsContext aContext, AnalysisEngineController aController) {
     context = aContext;
+    UIDGenerator idGenerator = new UIDGenerator();
     controller = aController;
-    threadGroup = new ThreadGroup("VmThreadGroup_"+controller.getComponentName());
+    threadGroup = new ThreadGroup("VmThreadGroup"+idGenerator.nextId()+"_"+controller.getComponentName());
   }
 
   public void addSpiListener(SpiListener listener) {
@@ -118,18 +120,33 @@
       UimaVmMessageDispatcher dispatcher = entry.getValue();
       dispatcher.stop();
     }
-    if ( executor.isShutdown() && threadGroup.activeCount() == 0) {
-      try {
-        threadGroup.destroy();
-      } catch ( Exception e) {
-        System.out.println("Thread Group:"+threadGroup.getName()+ " Still Has Active Threads. Current Count:"+threadGroup.activeCount());
+    new Thread(threadGroup.getParent(),threadGroup.getName()+":Reaper") {
+      public void run() {
+        while ( threadGroup.activeCount() > 0) {
+          synchronized(this) {
+            try {
+              threadGroup.list();
+              wait(1000);
+            } catch( InterruptedException ex) {
+              
+            }
+          }
+        }
+        try {
+          threadGroup.destroy();
+        } catch ( Exception e) {
+        } finally {
+          threadGroup = null;
+        }
       }
-    }
+    }.start();
   }
   public void destroy() {
     try {
       stopIt();
-    } catch ( Exception e) { e.printStackTrace();}
+    } catch ( Exception e) {
+      
+    }
   }
 
   protected ThreadPoolExecutor getExecutorInstance() {