Package ch.ivyteam.util.threadcontext
Class IvyAsyncRunner
java.lang.Object
ch.ivyteam.util.threadcontext.IvyAsyncRunner
Runs async code in the Ivy context which was active while the runner was created.
This allows the execution of code that runs against the ivy API in a any thread pool.
This allows the execution of code that runs against the ivy API in a any thread pool.
Sample:
//called within ivy context (e.g. Script Activity) IvyAsyncRunner asyncRunner = new IvyAsyncRunner(); Callable<String> slowFunction = ()->SomeAPI.call("hello", 12, TimeUnit.SECONDS); Future<String> asyncResult = Executors.newSingleThreadExecutor().submit(()->asyncRunner.run(slowFunction));
- Since:
- 7.3.0
- API:
- This is a public API.
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
IvyAsyncRunner
public IvyAsyncRunner()Creates the runner. Stores the Ivy context on creation to re-use it later in therun(Callable)
.- API:
- This public API is available in Java.
-
-
Method Details
-
run
- Parameters:
callable
- code to be executed asynchronously- Returns:
- result
- Throws:
Exception
- API:
- This public API is available in Java.
-
run
- Parameters:
runnable
- code to be executed asynchronously- API:
- This public API is available in Java.
-