alma::acs::concurrent::ThreadLoopRunner::CancelableRunnable Class Reference

Inheritance diagram for alma::acs::concurrent::ThreadLoopRunner::CancelableRunnable:
Inheritance graph
[legend]

List of all members.

Public Member Functions

void cancel ()

Protected Attributes

volatile boolean shouldTerminate = false

Detailed Description

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

  1. provide a subclass of this CancelableRunnable as the loop action in ThreadLoopRunner#ThreadLoopRunner(ThreadFactory, Runnable, Logger)
  2. implement 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.

Member Function Documentation

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.


Member Data Documentation

Referenced by cancel().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2