- java.lang.Object
-
- io.github.interacto.interaction.ThreadService
-
public class ThreadService extends Object
Replace the use of static Thread's methods by a service that one can mock easily.
-
-
Constructor Summary
Constructors Constructor Description ThreadService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadcurrentThread()Returns a reference to the currently executing thread object.static ThreadServicegetInstance()static voidsetInstance(ThreadService instance)Sets the single instance.voidsleep(long millis)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.
-
-
-
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 InterruptedExceptionCauses 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 ofmillisis negativeInterruptedException- 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.
-
-