Interface Stopwatch.StopwatchSet

  • All Superinterfaces:
    Stopwatch.Durations
    Enclosing class:
    Stopwatch

    @ThreadSafe
    public static interface Stopwatch.StopwatchSet
    extends Stopwatch.Durations
    A set of stopwatches whose durations are combined. New stopwatches can be created at any time, and when Stopwatch.stop() will always record their duration with this set.

    This set is threadsafe, meaning that multiple threads can create() new stopwatches concurrently, and each stopwatch's duration is measured separately. Additionally, all of the other methods of this interface are also threadsafe.

    • Method Detail

      • create

        Stopwatch create()
        Create a new stopwatch that records durations with this set.
        Returns:
        the new stopwatch; never null
      • time

        default void time​(Runnable runnable)
        Time the given function.
        Parameters:
        runnable - the function to call
      • time

        default <T> T time​(Callable<T> runnable)
        Time the given function.
        Parameters:
        runnable - the function that is to be executed; may not be null
        Returns:
        the result of the operation
      • time

        default void time​(int repeat,
                          Runnable runnable)
        Time the given function multiple times.
        Parameters:
        repeat - the number of times to repeat the function call; must be positive
        runnable - the function to call; may not be null
      • time

        default <T> void time​(int repeat,
                              Callable<T> runnable,
                              Consumer<T> cleanup)
                       throws Exception
        Time the given function multiple times.
        Parameters:
        repeat - the number of times to repeat the function call; must be positive
        runnable - the function that is to be executed a number of times; may not be null
        cleanup - the function that is to be called after each time call to the runnable function, and not included in the time measurements; may be null
        Throws:
        Exception - the exception thrown by the runnable function
      • await

        void await()
            throws InterruptedException
        Block until all running stopwatches have been stopped. This means that if a stopwatch is created but never started, this method will not wait for it. Likewise, if a stopwatch is created and started, then this method will block until the stopwatch is stopped (even if the same stopwatch is started multiple times). are stopped.
        Throws:
        InterruptedException - if the thread is interrupted before unblocking
      • await

        void await​(long timeout,
                   TimeUnit unit)
            throws InterruptedException
        Block until all stopwatches that have been created and started are stopped.
        Parameters:
        timeout - the maximum length of time that this method should block
        unit - the unit for the timeout; may not be null
        Throws:
        InterruptedException - if the thread is interrupted before unblocking