summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk/util
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main/java/com/orbekk/util')
-rw-r--r--same/src/main/java/com/orbekk/util/DelayedOperation.java32
1 files changed, 15 insertions, 17 deletions
diff --git a/same/src/main/java/com/orbekk/util/DelayedOperation.java b/same/src/main/java/com/orbekk/util/DelayedOperation.java
index c423a7d..7a7b808 100644
--- a/same/src/main/java/com/orbekk/util/DelayedOperation.java
+++ b/same/src/main/java/com/orbekk/util/DelayedOperation.java
@@ -1,5 +1,7 @@
package com.orbekk.util;
+import java.util.concurrent.CountDownLatch;
+
public class DelayedOperation {
public static class Status {
public final static int OK = 1;
@@ -65,10 +67,10 @@ public class DelayedOperation {
}
}
- private Status status;
- private boolean isDone;
- private int identifier;
-
+ private volatile Status status;
+ private volatile int identifier;
+ private final CountDownLatch done = new CountDownLatch(1);
+
public DelayedOperation() {
}
@@ -77,26 +79,22 @@ public class DelayedOperation {
return status;
}
- public synchronized void waitFor() {
- while (!isDone) {
- try {
- wait();
- } catch (InterruptedException e) {
- complete(new Status(Status.ERROR, "Thread interrupted."));
- }
+ public void waitFor() {
+ try {
+ done.await();
+ } catch (InterruptedException e) {
+ complete(new Status(Status.ERROR, "Thread interrupted."));
+ Thread.currentThread().interrupt();
}
}
public synchronized boolean isDone() {
- return isDone;
+ return done.getCount() <= 0;
}
public synchronized void complete(Status status) {
- if (!isDone) {
- isDone = true;
- this.status = status;
- notifyAll();
- }
+ this.status = status;
+ done.countDown();
}
public synchronized int getIdentifier() {