CallableBackgroundInitializer
- public class org.apache.commons.lang3.concurrent.CallableBackgroundInitializer<T> extends BackgroundInitializer<T>[source]
A specialized
BackgroundInitializerimplementation that wraps aCallableobject.An instance of this class is initialized with a
Callableobject when it is constructed. The implementation of the#initialize()method defined in the super class delegates to thisCallableso that theCallableis executed in the background thread.The
java.util.concurrent.Callableinterface is a standard mechanism of the JDK to define tasks to be executed by another thread. TheCallableBackgroundInitializerclass allows combining this standard interface with the background initializer API.Usage of this class is very similar to the default usage pattern of the
BackgroundInitializerclass: Just create an instance and provide theCallableobject to be executed, then call the initializer’s#start()method. This causes theCallableto be executed in another thread. When the results of theCallableare needed the initializer’s#get()method can be called (which may block until background execution is complete). The following code fragment shows a typical usage example:// a Callable that performs a complex computation Callable<Integer> computationCallable = new MyComputationCallable(); // setup the background initializer CallableBackgroundInitializer<Integer> initializer = new CallableBackgroundInitializer(computationCallable); initializer.start(); // Now do some other things. Initialization runs in a parallel thread ... // Wait for the end of initialization and access the result Integer result = initializer.get();
- Parameters:
<T> – The type of the object managed by this initializer class
- Since:
3.0
Constructors
Creates a new instance of |
|
Creates a new instance of |
- public CallableBackgroundInitializer(Callable<T> call)[source]
Creates a new instance of
CallableBackgroundInitializerand sets theCallableto be executed in a background thread.
- public CallableBackgroundInitializer(Callable<T> call, ExecutorService exec)[source]
Creates a new instance of
CallableBackgroundInitializerand initializes it with theCallableto be executed in a background thread and theExecutorServicefor managing the background execution.- Parameters:
call – The
Callable(must not benull).exec – An external
ExecutorServiceto be used for task execution.
- Throws:
java.lang.IllegalArgumentException – Thrown if the
Callableisnull.
Methods
Gets an Exception with a type of E as defined by a concrete subclass of this class. |
|
Performs initialization in a background thread. |