You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2007/02/08 15:29:59 UTC

svn commit: r504911 - /incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/ProcessingContainer_Impl.java

Author: schor
Date: Thu Feb  8 06:29:58 2007
New Revision: 504911

URL: http://svn.apache.org/viewvc?view=rev&rev=504911
Log:
UIMA-284 4 changes:  

1) Renamed the lock to clarify it only is used to
synch access to 1 variable, and added some comments about this

2) moved the test leading to a wait under the same lock
used by the wait to avoid a race condition

3) changed the wait to not have a timeout.  Timeout isn't 
needed.  

4) changed the public getter of the field under control of 
this lock to use the lock when reading the variable (to 
get the right value, per JVM memory model)

Modified:
    incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/ProcessingContainer_Impl.java

Modified: incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/ProcessingContainer_Impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/ProcessingContainer_Impl.java?view=diff&rev=504911&r1=504910&r2=504911
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/ProcessingContainer_Impl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/ProcessingContainer_Impl.java Thu Feb  8 06:29:58 2007
@@ -142,11 +142,14 @@
 
   private HashMap statMap = new HashMap();
 
+  // access this only under monitor lock
+  //   monitor.notifyall called when switching from true -> false
   private boolean isPaused = false;
 
   private boolean singleFencedInstance = false;
 
-  private final Object monitor = new Object();
+  // This lock used only for isPaused field
+  private final Object lockForIsPaused = new Object();
 
   private String processorName = null;
 
@@ -1099,29 +1102,32 @@
     // the CPM is trying to reconnect to the fenced un-managed service. Needed to make
     // sure that all threads using the same remote service pause until connection is
     // re-established. This loop will be terminated when the CPM calls resume().
-    while (isPaused()) {
-      try {
-        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
-          UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
-                  "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_container_paused__FINEST",
-                  new Object[] { Thread.currentThread().getName(), getName() });
-        }
-        synchronized (monitor) {
-          monitor.wait(CONTAINER_SLEEP_TIME);
+    synchronized (lockForIsPaused) {
+      while (isPaused) {
+        try {
+          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
+            UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
+                    "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
+                    "UIMA_CPM_container_paused__FINEST",
+                    new Object[] { Thread.currentThread().getName(), getName() });
+          }
+
+          lockForIsPaused.wait();
+
+        } catch (InterruptedException e) {
         }
-      } catch (InterruptedException e) {
-      }
 
-      if (!isPaused) {
-        if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
-          UIMAFramework.getLogger(this.getClass()).logrb(
-                  Level.FINEST,
-                  this.getClass().getName(),
-                  "process",
-                  CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
-                  "UIMA_CPM_resuming_container__FINEST",
-                  new Object[] { Thread.currentThread().getName(), getName(),
-                      String.valueOf(CONTAINER_SLEEP_TIME) });
+        if (!isPaused) {
+          if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
+            UIMAFramework.getLogger(this.getClass()).logrb(
+                    Level.FINEST,
+                    this.getClass().getName(),
+                    "process",
+                    CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
+                    "UIMA_CPM_resuming_container__FINEST",
+                    new Object[] { Thread.currentThread().getName(), getName(),
+                        String.valueOf(CONTAINER_SLEEP_TIME) });
+          }
         }
       }
     }
@@ -1509,23 +1515,27 @@
               "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_pause_container__FINEST",
               new Object[] { Thread.currentThread().getName(), getName() });
     }
-    isPaused = true;
+    synchronized (lockForIsPaused) {
+      isPaused = true;
+    }
   }
 
   public void resume() {
-    synchronized (monitor) {
+    synchronized (lockForIsPaused) {
       if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
         UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
                 "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_resuming_container__FINEST",
                 new Object[] { Thread.currentThread().getName(), getName() });
       }
       isPaused = false;
-      monitor.notifyAll();
+      lockForIsPaused.notifyAll();
     }
   }
 
   public boolean isPaused() {
-    return this.isPaused;
+    synchronized (lockForIsPaused) {
+      return this.isPaused;
+    }
   }
 
   public ServiceProxyPool getPool() {