/** * Create a thread that will interrupt the calling thread when the {@link TimeSince elapsed time} has exceeded the * specified amount. The supplied {@link TimeSince} object will be {@link TimeSince#reset() reset} when the * new thread is started, and should also be {@link TimeSince#reset() reset} any time the elapsed time should be reset to 0. * * @param threadName the name of the new thread; may not be null * @param timeout the maximum amount of time that can elapse before the thread is interrupted; must be positive * @param timeoutUnit the unit for {@code timeout}; may not be null * @param elapsedTimer the component used to measure the elapsed time; may not be null * @return the new thread that has not yet been {@link Thread#start() started}; never null */ public static Thread interruptAfterTimeout(String threadName, long timeout, TimeUnit timeoutUnit, TimeSince elapsedTimer) { Thread threadToInterrupt = Thread.currentThread(); return interruptAfterTimeout(threadName, timeout, timeoutUnit, elapsedTimer, threadToInterrupt); }
/** * Create a thread that will interrupt the calling thread when the {@link TimeSince elapsed time} has exceeded the * specified amount. The supplied {@link TimeSince} object will be {@link TimeSince#reset() reset} when the * new thread is started, and should also be {@link TimeSince#reset() reset} any time the elapsed time should be reset to 0. * * @param threadName the name of the new thread; may not be null * @param timeout the maximum amount of time that can elapse before the thread is interrupted; must be positive * @param timeoutUnit the unit for {@code timeout}; may not be null * @param elapsedTimer the component used to measure the elapsed time; may not be null * @return the new thread that has not yet been {@link Thread#start() started}; never null */ public static Thread interruptAfterTimeout(String threadName, long timeout, TimeUnit timeoutUnit, TimeSince elapsedTimer) { Thread threadToInterrupt = Thread.currentThread(); return interruptAfterTimeout(threadName, timeout, timeoutUnit, elapsedTimer, threadToInterrupt); }