2.6 Obtaining The Reactor Uptime

The reactor's user interface provides a mechanism for reading back the current time, as given by the monotonic clock source. This may be interpreted as the current uptime of the reactor component, specified as an integer number of milliseconds using a Java native long integer. The API for accessing the current reactor uptime is illustrated in Listing 2.8.


\begin{listing}
% latex2html id marker 451\begin{small}\begin{verbatim}packa...
...
}\end{verbatim} \end{small}\caption{Reactor Uptime Getter Method}
\end{listing}


\begin{listing}
% latex2html id marker 459\begin{small}\begin{verbatim}...
...
...im} \end{small}\caption{Example Code for Accessing Reactor Uptime}
\end{listing}

The reactor's getUptime method may be called from any thread context in order to obtain the current uptime. An example of this method call in use is illustrated by the code fragment shown in Listing 2.9. This code fragment may be used to replace the delay introduced by the Thread.sleep call in the reactor lifecycle example of Listing 2.7. A full implementation of this example is included in the reactor examples package as ReactorUptimeExample.