Package cc.redberry.rings.util
Class TimeConstrained
- java.lang.Object
-
- cc.redberry.rings.util.TimeConstrained
-
public class TimeConstrained extends Object
-
-
Constructor Summary
Constructors Constructor Description TimeConstrained()
-
Method Summary
Modifier and Type Method Description static <T> T
timeConstrained(Callable<T> lambda, long millis)
Runs lambda, stopping after specified number of millisecondsstatic <T> T
timeConstrained(Callable<T> lambda, long millis, T failExpr)
Runs lambda, stopping after specified number of millisecondsstatic <T> T
timeConstrained0(Callable<T> lambda, long millis, T failExpr)
Runs lambda, stopping after specified number of milliseconds
-
-
-
Method Detail
-
timeConstrained0
public static <T> T timeConstrained0(Callable<T> lambda, long millis, T failExpr) throws InterruptedException, ExecutionException
Runs lambda, stopping after specified number of milliseconds- Parameters:
lambda
- code blockmillis
- time constrained in millisecondsfailExpr
- returns this if the time constraint is not met- Throws:
InterruptedException
ExecutionException
-
timeConstrained
public static <T> T timeConstrained(Callable<T> lambda, long millis, T failExpr)
Runs lambda, stopping after specified number of milliseconds- Parameters:
lambda
- code blockmillis
- time constrained in millisecondsfailExpr
- returns this if the time constraint is not met
-
timeConstrained
public static <T> T timeConstrained(Callable<T> lambda, long millis) throws InterruptedException, ExecutionException
Runs lambda, stopping after specified number of milliseconds- Parameters:
lambda
- code blockmillis
- time constrained in milliseconds- Throws:
InterruptedException
ExecutionException
-
-