A specialized {@link BackgroundInitializer} implementation that can deal withmultiple background initialization tasks.
This class has a similar purpose as {@link BackgroundInitializer}. However, it is not limited to a single background initialization task. Rather it manages an arbitrary number of {@code BackgroundInitializer} objects,executes them, and waits until they are completely initialized. This is useful for applications that have to perform multiple initialization tasks that can run in parallel (i.e. that do not depend on each other). This class takes care about the management of an {@code ExecutorService} and shares itwith the {@code BackgroundInitializer} objects it is responsible for; so theusing application need not bother with these details.
The typical usage scenario for {@code MultiBackgroundInitializer} is asfollows:
{@code MultiBackgroundInitializer} starts a special controller task thatstarts all {@code BackgroundInitializer} objects added to the instance.Before the an initializer is started it is checked whether this initializer already has an {@code ExecutorService} set. If this is the case, this {@code ExecutorService} is used for running the background task. Otherwise thecurrent {@code ExecutorService} of this {@code MultiBackgroundInitializer} isshared with the initializer.
The easiest way of using this class is to let it deal with the management of an {@code ExecutorService} itself: If no external {@code ExecutorService} isprovided, the class creates a temporary {@code ExecutorService} (that iscapable of executing all background tasks in parallel) and destroys it at the end of background processing.
Alternatively an external {@code ExecutorService} can be provided - either atconstruction time or later by calling the {@link #setExternalExecutor(ExecutorService)} method. In this case allbackground tasks are scheduled at this external {@code ExecutorService}. Important note: When using an external {@code ExecutorService} be sure that the number of threads managed by the service islarge enough. Otherwise a deadlock can happen! This is the case in the following scenario: {@code MultiBackgroundInitializer} starts a task thatstarts all registered {@code BackgroundInitializer} objects and waits fortheir completion. If for instance a single threaded {@code ExecutorService}is used, none of the background tasks can be executed, and the task created by {@code MultiBackgroundInitializer} waits forever.
@version $Id: MultiBackgroundInitializer.java 889215 2009-12-10 11:56:38Z bayard $
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|