Class ThreadService


  • public class ThreadService
    extends Object
    Replace the use of static Thread's methods by a service that one can mock easily.
    • Constructor Detail

      • ThreadService

        public ThreadService()
    • Method Detail

      • getInstance

        public static ThreadService getInstance()
        Returns:
        The single instance of ThreadService.
      • setInstance

        public static void setInstance​(ThreadService instance)
        Sets the single instance.
        Parameters:
        instance - The instance to use.
      • sleep

        public void sleep​(long millis)
                   throws InterruptedException
        Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.
        Parameters:
        millis - the length of time to sleep in milliseconds
        Throws:
        IllegalArgumentException - if the value of millis is negative
        InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
      • currentThread

        public Thread currentThread()
        Returns a reference to the currently executing thread object.
        Returns:
        the currently executing thread.