/** * Sets an {@code ExecutorService} to be used by this class. The {@code * ExecutorService} passed to this method is used for executing the * background task. Thus it is possible to re-use an already existing * {@code ExecutorService} or to use a specially configured one. If no * {@code ExecutorService} is set, this instance creates a temporary one and * destroys it after background initialization is complete. Note that this * method must be called before {@link #start()}; otherwise an exception is * thrown. * * @param externalExecutor the {@code ExecutorService} to be used * @throws IllegalStateException if this initializer has already been * started */ public final synchronized void setExternalExecutor( final ExecutorService externalExecutor) { if (isStarted()) { throw new IllegalStateException( "Cannot set ExecutorService after start()!"); } this.externalExecutor = externalExecutor; }
/** * Starts the background initialization. With this method the initializer * becomes active and invokes the {@link #initialize()} method in a * background task. A {@code BackgroundInitializer} can be started exactly * once. The return value of this method determines whether the start was * successful: only the first invocation of this method returns <b>true</b>, * following invocations will return <b>false</b>. * * @return a flag whether the initializer could be started successfully */ public synchronized boolean start() { // Not yet started? if (!isStarted()) { // Determine the executor to use and whether a temporary one has to // be created ExecutorService tempExec; executor = getExternalExecutor(); if (executor == null) { executor = tempExec = createExecutor(); } else { tempExec = null; } future = executor.submit(createTask(tempExec)); return true; } return false; }
/** * Sets an {@code ExecutorService} to be used by this class. The {@code * ExecutorService} passed to this method is used for executing the * background task. Thus it is possible to re-use an already existing * {@code ExecutorService} or to use a specially configured one. If no * {@code ExecutorService} is set, this instance creates a temporary one and * destroys it after background initialization is complete. Note that this * method must be called before {@link #start()}; otherwise an exception is * thrown. * * @param externalExecutor the {@code ExecutorService} to be used * @throws IllegalStateException if this initializer has already been * started */ public final synchronized void setExternalExecutor( final ExecutorService externalExecutor) { if (isStarted()) { throw new IllegalStateException( "Cannot set ExecutorService after start()!"); } this.externalExecutor = externalExecutor; }
/** * Sets an {@code ExecutorService} to be used by this class. The {@code * ExecutorService} passed to this method is used for executing the * background task. Thus it is possible to re-use an already existing * {@code ExecutorService} or to use a specially configured one. If no * {@code ExecutorService} is set, this instance creates a temporary one and * destroys it after background initialization is complete. Note that this * method must be called before {@link #start()}; otherwise an exception is * thrown. * * @param externalExecutor the {@code ExecutorService} to be used * @throws IllegalStateException if this initializer has already been * started */ public final synchronized void setExternalExecutor( final ExecutorService externalExecutor) { if (isStarted()) { throw new IllegalStateException( "Cannot set ExecutorService after start()!"); } this.externalExecutor = externalExecutor; }
/** * Sets an {@code ExecutorService} to be used by this class. The {@code * ExecutorService} passed to this method is used for executing the * background task. Thus it is possible to re-use an already existing * {@code ExecutorService} or to use a specially configured one. If no * {@code ExecutorService} is set, this instance creates a temporary one and * destroys it after background initialization is complete. Note that this * method must be called before {@link #start()}; otherwise an exception is * thrown. * * @param externalExecutor the {@code ExecutorService} to be used * @throws IllegalStateException if this initializer has already been * started */ public final synchronized void setExternalExecutor( final ExecutorService externalExecutor) { if (isStarted()) { throw new IllegalStateException( "Cannot set ExecutorService after start()!"); } this.externalExecutor = externalExecutor; }
/** * Starts the background initialization. With this method the initializer * becomes active and invokes the {@link #initialize()} method in a * background task. A {@code BackgroundInitializer} can be started exactly * once. The return value of this method determines whether the start was * successful: only the first invocation of this method returns <b>true</b>, * following invocations will return <b>false</b>. * * @return a flag whether the initializer could be started successfully */ public synchronized boolean start() { // Not yet started? if (!isStarted()) { // Determine the executor to use and whether a temporary one has to // be created ExecutorService tempExec; executor = getExternalExecutor(); if (executor == null) { executor = tempExec = createExecutor(); } else { tempExec = null; } future = executor.submit(createTask(tempExec)); return true; } return false; }
/** * Starts the background initialization. With this method the initializer * becomes active and invokes the {@link #initialize()} method in a * background task. A {@code BackgroundInitializer} can be started exactly * once. The return value of this method determines whether the start was * successful: only the first invocation of this method returns <b>true</b>, * following invocations will return <b>false</b>. * * @return a flag whether the initializer could be started successfully */ public synchronized boolean start() { // Not yet started? if (!isStarted()) { // Determine the executor to use and whether a temporary one has to // be created ExecutorService tempExec; executor = getExternalExecutor(); if (executor == null) { executor = tempExec = createExecutor(); } else { tempExec = null; } future = executor.submit(createTask(tempExec)); return true; } return false; }
/** * Starts the background initialization. With this method the initializer * becomes active and invokes the {@link #initialize()} method in a * background task. A {@code BackgroundInitializer} can be started exactly * once. The return value of this method determines whether the start was * successful: only the first invocation of this method returns <b>true</b>, * following invocations will return <b>false</b>. * * @return a flag whether the initializer could be started successfully */ public synchronized boolean start() { // Not yet started? if (!isStarted()) { // Determine the executor to use and whether a temporary one has to // be created ExecutorService tempExec; executor = getExternalExecutor(); if (executor == null) { executor = tempExec = createExecutor(); } else { tempExec = null; } future = executor.submit(createTask(tempExec)); return true; } return false; }