diff --git a/rosjava/src/main/java/org/ros/concurrent/CancellableLoop.java b/rosjava/src/main/java/org/ros/concurrent/CancellableLoop.java
index fa6bc0ba6..b340d7666 100644
--- a/rosjava/src/main/java/org/ros/concurrent/CancellableLoop.java
+++ b/rosjava/src/main/java/org/ros/concurrent/CancellableLoop.java
@@ -16,49 +16,45 @@
package org.ros.concurrent;
-import com.google.common.base.Preconditions;
-
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
/**
* An interruptable loop that can be run by an {@link ExecutorService}.
- *
+ *
* @author khughes@google.com (Keith M. Hughes)
*/
public abstract class CancellableLoop implements Runnable {
+ private static final Object NOT_STARTED = null;
- private final Object mutex;
-
- /**
- * {@code true} if the code has been run once, {@code false} otherwise.
- */
- private boolean ranOnce = false;
+ private static final Object FINISHED = CancellableLoop.class;
/**
- * The {@link Thread} the code will be running in.
+ * State of this loop. Possible values are:
+ *
+ *
{@link #NOT_STARTED} - corresponds to the 'initial' state, before the loop starts
+ *
{@link Thread} - 'running' state
+ *
{@link #FINISHED} - 'finished' state (this can be an arbitrary object)
+ *
*/
- private Thread thread;
-
- public CancellableLoop() {
- mutex = new Object();
- }
+ private final AtomicReference