handled correct clean up in distributed worker reset
@@ -68,6 +68,7 @@ public class ODistributedWorker extends Thread {
private static final long MAX_SHUTDOWN_TIMEOUT = 5000l;
private volatile ODistributedRequest currentExecuting;
+ private volatile boolean executingMessage;
public ODistributedWorker(final ODistributedDatabaseImpl iDistributed, final String iDatabaseName, final int i,
final boolean acceptsWhileNotOnline) {
@@ -115,14 +116,20 @@ public class ODistributedWorker extends Thread {
try {
message = readRequest();
+ synchronized (this) {
+ executingMessage = true;
currentExecuting = message;
-
+ }
if (message != null) {
manager.messageProcessStart(message);
message.getId();
reqId = message.getId();
onMessage(message);
}
+ synchronized (this) {
+ executingMessage = false;
+ this.notify();
+ }
} catch (InterruptedException e) {
// EXIT CURRENT THREAD
@@ -480,6 +487,7 @@ public class ODistributedWorker extends Thread {
}
public void reset() {
+ synchronized (this) {
ODistributedRequest el;
do {
el = localQueue.poll();
@@ -487,6 +495,14 @@ public class ODistributedWorker extends Thread {
el.getTask().finished();
}
} while (el != null);
+
+ if (executingMessage) {
+ try {
+ this.wait(MAX_SHUTDOWN_TIMEOUT);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
ODistributedRequest process = currentExecuting;
if (process != null) {
process.getTask().finished();
@@ -496,6 +512,7 @@ public class ODistributedWorker extends Thread {
database.close();
database = null;
}
+ }
}
