From 4bd439e6157184ce847ec28101d64203f1cedea2 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Fri, 22 Mar 2013 16:51:32 +0100 Subject: [PATCH] modification to worker to allow integration in other project --- java/src/mimis/worker/Worker.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/java/src/mimis/worker/Worker.java b/java/src/mimis/worker/Worker.java index 2371cb9..7c41120 100644 --- a/java/src/mimis/worker/Worker.java +++ b/java/src/mimis/worker/Worker.java @@ -12,24 +12,31 @@ public abstract class Worker implements Runnable { protected static final boolean THREAD = false; protected static final int SLEEP = 100; + protected boolean thread = true; protected boolean interrupt; protected boolean run = false; protected boolean active = false; protected boolean activate = false; protected boolean deactivate = false; - public final void start(boolean thread) { + public Worker() {} + + public Worker(boolean thread) { + this.thread = thread; + } + + public synchronized final void start(boolean thread) { if (!active) { activate = true; } if (!run) { run = true; if (thread) { - log.debug("Run directly"); - run(); - } else { log.debug("Start thread"); new Thread(this, getClass().getName()).start(); + } else { + log.debug("Run directly"); + run(); } } else { notifyAll(); @@ -37,7 +44,7 @@ public abstract class Worker implements Runnable { } public synchronized final void start() { - start(THREAD); + start(thread); } public synchronized final void stop() {