public class TimeLimiter extends Object
Constructor and Description |
---|
TimeLimiter() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
callWithTimeout(Callable<T> callable,
long timeoutDuration,
TimeUnit timeoutUnit)
Invokes a specified Callable with the specified time limit.
|
void |
runWithTimeout(Runnable runnable,
long timeoutDuration,
TimeUnit timeoutUnit)
Invokes a specified Runnable with the specified time limit.
|
public static <T> T callWithTimeout(Callable<T> callable, long timeoutDuration, TimeUnit timeoutUnit) throws Exception
TimeoutException
to the caller.T
- the type of the task's resultcallable
- the Callable to executetimeoutDuration
- with timeoutUnit, the maximum length of time to waittimeoutUnit
- with timeoutDuration, the maximum length of time to waitException
- if the time limit is reached, the thread is interrupted, or an exception
is thrown during execution.public void runWithTimeout(Runnable runnable, long timeoutDuration, TimeUnit timeoutUnit) throws Exception
TimeoutException
to the caller.runnable
- the Runnable to executetimeoutDuration
- with timeoutUnit, the maximum length of time to waittimeoutUnit
- with timeoutDuration, the maximum length of time to waitException
- if the time limit is reached, the thread is interrupted, or an exception
is thrown during execution.Copyright © 2023 ScalAgent D.T.. All rights reserved.