
Public Member Functions | |
| void | cancel () |
Protected Attributes | |
| volatile boolean | shouldTerminate = false |
Variation of Runnable that allows other threads to give a hint to the {run() method that it should terminate. This is useful mainly with implementations of run() that don't finish immediately. Note that in Java Thread#stop() and similar methods are deprecated, and that the proper way to terminate asynchronously running code is to signal the termination request via some variable that the thread is supposed to check at convenient points.
Therefore if your run method takes non-negligible time, you should
CancelableRunnable as the loop action in ThreadLoopRunner#ThreadLoopRunner(ThreadFactory, Runnable, Logger) run() to check at some points whether the flag shouldTerminate has been set (e.g. by ThreadLoopRunner#shutdown calling CancelableRunnable#cancel()), and if so, to return from the run method as quickly as possible, but yet cleaning up. | void alma::acs::concurrent::ThreadLoopRunner::CancelableRunnable::cancel | ( | ) | [inline] |
Either the subclass's run() method evaluates the "shouldTerminate" flag, or the cancel() method gets overridden so that the subclass can react directly to it.
References shouldTerminate.
volatile boolean alma::acs::concurrent::ThreadLoopRunner::CancelableRunnable::shouldTerminate = false [protected] |
Referenced by cancel().
1.6.2