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/20 17:26:49 UTC
svn commit: r806214 -
/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java
Author: cwiklik
Date: Thu Aug 20 15:26:47 2009
New Revision: 806214
URL: http://svn.apache.org/viewvc?rev=806214&view=rev
Log:
UIMA-1439 prevent stopIt() from executing by more than one thread. This problem fixes NPE and a race condition during service shutdown
Modified:
incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java
Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java?rev=806214&r1=806213&r2=806214&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/spi/transport/vm/VmTransport.java Thu Aug 20 15:26:47 2009
@@ -28,6 +28,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.uima.aae.UIDGenerator;
import org.apache.uima.aae.UimaAsContext;
@@ -71,6 +72,8 @@
private AnalysisEngineController controller;
private UimaAsContext context;
+
+ private AtomicBoolean stopping = new AtomicBoolean(false);
public VmTransport(UimaAsContext aContext, AnalysisEngineController aController) {
context = aContext;
@@ -112,6 +115,10 @@
}
public synchronized void stopIt() throws UimaSpiException {
+ if ( stopping.get() == true ) {
+ return;
+ }
+ stopping.set(true);
executor.purge();
executor.shutdownNow();
workQueue.clear();
@@ -121,8 +128,10 @@
dispatcher.stop();
}
if ( threadGroup != null ) {
- new Thread(threadGroup.getParent(),threadGroup.getName()+":Reaper") {
+ // Spin a thread where we wait for threads in the threadGroup to stop.
+ new Thread(threadGroup.getParent(),threadGroup.getName()+":Reaper") {
public void run() {
+
while ( threadGroup.activeCount() > 0) {
synchronized(this) {
try {