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 23:12:12 UTC
svn commit: r505053 -
/incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/Checkpoint.java
Author: schor
Date: Thu Feb 8 14:12:11 2007
New Revision: 505053
URL: http://svn.apache.org/viewvc?view=rev&rev=505053
Log:
UIMA-284 7 changes.
1) Make class variables that might be read/set under multiple
threads, but which are not otherwise guarded by an explicit lock,
"volatile".
2) Rename the lock object to indicate what field it is being
used to guard.
3) Remove the sleepMonitor. Replace that construct with the
equivalent but simpler Thread.sleep(timeout).
4) Eliminate race condition: move test of "pause" inside
synch block.
5) Change catch for wait() to be specific instead of Exception
6) Put all code which changes the "pause" field under synch
of its guard lock.
7) remove unneeded try/catch around "notifyAll"
Modified:
incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/Checkpoint.java
Modified: incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/Checkpoint.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/Checkpoint.java?view=diff&rev=505053&r1=505052&r2=505053
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/Checkpoint.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/Checkpoint.java Thu Feb 8 14:12:11 2007
@@ -42,15 +42,17 @@
public class Checkpoint implements Runnable {
private String fileName = null;
- private boolean stop = false;
+ private volatile boolean stop = false; // volatile may be buggy in some JVMs apparently
+ // consider changing to use synch
private long checkpointFrequency = 3000;
+ /**
+ * @GuardedBy(lockForPause)
+ */
private boolean pause = false;
- private final Object monitor = new Object();
-
- private final Object sleepMonitor = new Object();
+ private final Object lockForPause = new Object();
// private boolean isRunning = false;
private BaseCPMImpl cpm = null;
@@ -106,11 +108,11 @@
// isRunning = true;
while (!stop) {
- if (pause) {
- synchronized (monitor) {
+ synchronized (lockForPause) {
+ if (pause) {
try {
- monitor.wait();
- } catch (Exception e) {
+ lockForPause.wait();
+ } catch (InterruptedException e) {
}
}
}
@@ -121,24 +123,21 @@
}
doCheckpoint();
- synchronized (sleepMonitor) {
- 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_sleep__FINEST",
- new Object[] { Thread.currentThread().getName() });
- }
- sleepMonitor.wait(checkpointFrequency);
- if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
- UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
- "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_wakeup__FINEST",
- new Object[] { Thread.currentThread().getName() });
- }
- } catch (Exception e) {
+ 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_sleep__FINEST",
+ new Object[] { Thread.currentThread().getName() });
}
+ Thread.sleep(checkpointFrequency);
+ if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
+ UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
+ "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_wakeup__FINEST",
+ new Object[] { Thread.currentThread().getName() });
+ }
+ } catch (Exception e) {
}
}
-
}
/**
@@ -160,7 +159,9 @@
*
*/
public void pause() {
- pause = true;
+ synchronized (lockForPause) {
+ pause = true;
+ }
}
/**
@@ -168,16 +169,12 @@
*
*/
public void resume() {
- synchronized (monitor) {
+ synchronized (lockForPause) {
if (pause) {
- try {
- monitor.notifyAll();
- } catch (Exception e) {
- }
+ lockForPause.notifyAll();
pause = false;
}
}
-
}
/**