T
- the type of the object managed by this initializer classpublic class CallableBackgroundInitializer<T> extends BackgroundInitializer<T>
A specialized BackgroundInitializer
implementation that wraps a
Callable
object.
An instance of this class is initialized with a Callable
object when
it is constructed. The implementation of the initialize()
method
defined in the super class delegates to this Callable
so that the
Callable
is executed in the background thread.
The java.util.concurrent.Callable
interface is a standard mechanism
of the JDK to define tasks to be executed by another thread. The CallableBackgroundInitializer
class allows combining this standard interface
with the background initializer API.
Usage of this class is very similar to the default usage pattern of the
BackgroundInitializer
class: Just create an instance and provide the
Callable
object to be executed, then call the initializer's
BackgroundInitializer.start()
method. This causes the Callable
to be executed in
another thread. When the results of the Callable
are needed the
initializer's BackgroundInitializer.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();
Constructor and Description |
---|
CallableBackgroundInitializer(java.util.concurrent.Callable<T> call)
Creates a new instance of
CallableBackgroundInitializer and sets
the Callable to be executed in a background thread. |
CallableBackgroundInitializer(java.util.concurrent.Callable<T> call,
java.util.concurrent.ExecutorService exec)
Creates a new instance of
CallableBackgroundInitializer and
initializes it with the Callable to be executed in a background
thread and the ExecutorService for managing the background
execution. |
get, getExternalExecutor, getFuture, isStarted, setExternalExecutor, start
public CallableBackgroundInitializer(java.util.concurrent.Callable<T> call)
CallableBackgroundInitializer
and sets
the Callable
to be executed in a background thread.call
- the Callable
(must not be null)java.lang.IllegalArgumentException
- if the Callable
is nullpublic CallableBackgroundInitializer(java.util.concurrent.Callable<T> call, java.util.concurrent.ExecutorService exec)
CallableBackgroundInitializer
and
initializes it with the Callable
to be executed in a background
thread and the ExecutorService
for managing the background
execution.call
- the Callable
(must not be null)exec
- an external ExecutorService
to be used for task
executionjava.lang.IllegalArgumentException
- if the Callable
is nullCopyright © 2010 - 2020 Adobe. All Rights Reserved