- synchronized (c_lock) {
- if (false == threadRunning()) {
- return; // stopped before it ever started. how can this be? we just got invoked.
+ if (!threadAlive()) {
+ return; // stopped before it ever started. how can this be? we just got invoked.
+ }
+ try {
+ while (true) {
+ boolean keepGoing = performActivity();
+ if (!keepGoing) {
+ c_logger.debug("thread returned false, signifying it wants to exit. now dropping it.");
+ break;
+ }
+ if (c_period == 0) {
+ // not a periodic thread, so we're done now.
+ break;
+ }
+ long nextRun = System.currentTimeMillis() + c_period;
+ while (System.currentTimeMillis() < nextRun) {
+ if (shouldStop()) {
+ break;
+ }
+ try {
+ Thread.sleep(SNOOZE_PERIOD);
+ } catch (InterruptedException e) {
+ // well, we'll hit it again soon.
+ }
+ }