Inspired by Actual Events: Guava Stopwatch
I have already alluded to several caveats to keep in mind when using Guava's Stopwatch
. First, two successive start()
methods should not be invoked on a given instance of Stopwatch
without first stopping it with stop()
before making the second call to stop()
. Stopwatch
has an instance method isRunning() that is useful for detecting a running stopwatch before trying to start it again or even before trying to stop one that has already been stopped or was never started. Most of these issues such as starting the stopwatch twice without stopping it or stopping a stopwatch that is not running or was never started lead to IllegalStateExceptions being thrown. Guava developers make use of their own Preconditions class to ascertain these aberrant conditions and to the throwing of these exceptions. The further implication of this, which is spelled out in the Javadoc documentation, is that Stopwatch
is not thread-safe and should be used in a single-thread environment.
Read full article from Inspired by Actual Events: Guava Stopwatch
No comments:
Post a Comment