1 package org.feistymeow.process;
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
7 * A simple java thread that hearkens back to the HOOPLE C++ ethread in features.
9 * @author Chris Koeritz
10 * @copyright Copyright (c) 2010-$now By Feisty Meow Concerns Ltd.
11 * @license This file is free software; you can modify and redistribute it under the terms of the
12 * Apache License v2.0: http://www.apache.org/licenses/LICENSE-2.0
14 public abstract class ethread implements Runnable
16 private static Log c_logger = LogFactory.getLog(ethread.class);
18 // the actual java thread object.
19 private volatile Thread c_RealThread = null;
20 // provides synchronization for the thread.
21 private volatile Object c_lock = new Object();
24 * creates a new ethread without starting it.
31 * Begins execution of the thread.
35 synchronized (c_lock) {
36 if (null == this.c_RealThread) {
37 this.c_RealThread = new Thread(this);
38 c_logger.debug("starting thread " + c_RealThread.getId());
39 this.c_RealThread.start();
45 * Stops execution of the thread, or at least attempts to.
49 synchronized (c_lock) {
50 Thread goAway = c_RealThread;
59 * this is the main function that derived classes must implement. it does the actual work that
60 * the thread is intended to perform. note that the derived version must not do anything to
61 * cause the thread to be ripped out while performActivity is still being invoked.
63 // hmmm: should this stay void, or use a bool status to indicate if the thread should die?
64 abstract void performActivity();
67 * Returns true if the thread isn't null.
69 public boolean threadRunning()
71 synchronized (c_lock) {
72 return (null != this.c_RealThread);
77 * this is the override from Runnable that allows us to call our own performActivity method.
78 * implementors should not override this; they should override performActivity instead.
82 synchronized (c_lock) {
83 if (false == threadRunning()) {
84 return; // stopped before it ever started. how can this be? we just got invoked.
91 // hmmm: still in progress...
92 // hmmm: missing the timed features of ethread.
93 // hmmm: missing cancel, exempt_stop, sleep_time, should_stop,