Class ThreadHelper
java.lang.Object
org.sentrysoftware.metricshub.engine.common.helpers.ThreadHelper
Provides utility methods for thread management, including executing tasks
with a specified timeout. This class is part of the MetricsHub Engine's
common helper utilities.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ThreadHelper
public ThreadHelper()
-
-
Method Details
-
execute
public static <T> T execute(Callable<T> callable, long timeout) throws InterruptedException, ExecutionException, TimeoutException Executes aCallabletask with a specified timeout. This method creates a single-threaded executor to run the provided task. If the task completes within the given timeout, its result is returned. Otherwise, aTimeoutExceptionis thrown.- Type Parameters:
T- the type of the result returned by thecallable- Parameters:
callable- the task to be executedtimeout- the maximum time to wait for the task to complete, in seconds- Returns:
- the result of the executed task
- Throws:
InterruptedException- if the current thread was interrupted while waitingExecutionException- if the computation threw an exceptionTimeoutException- if the wait timed out
-