This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit cef50874363d7ab71e0ec9af3b5ec4d3b5d8b3f5 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jun 14 14:12:54 2025 -0400 Javadoc --- .../lang3/concurrent/BackgroundInitializer.java | 62 +++++++++------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/concurrent/BackgroundInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/BackgroundInitializer.java index ad5a71602..91f4b2681 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/BackgroundInitializer.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/BackgroundInitializer.java @@ -195,7 +195,7 @@ protected BackgroundInitializer() { * scheduled at this service. Otherwise a new temporary {@code * ExecutorService} is created. * - * @param exec an external {@link ExecutorService} to be used for task + * @param exec an external {@link ExecutorService} to be used for task. * execution */ protected BackgroundInitializer(final ExecutorService exec) { @@ -218,7 +218,7 @@ private BackgroundInitializer(final FailableSupplier<T, ConcurrentException> ini * Creates the {@link ExecutorService} to be used. This method is called if * no {@link ExecutorService} was provided at construction time. * - * @return the {@link ExecutorService} to be used + * @return the {@link ExecutorService} to be used. */ private ExecutorService createExecutor() { return Executors.newFixedThreadPool(getTaskCount()); @@ -232,15 +232,15 @@ private ExecutorService createExecutor() { * at the end of the task. * * @param execDestroy the {@link ExecutorService} to be destroyed by the - * task - * @return a task for the background initialization + * task. + * @return a task for the background initialization. */ private Callable<T> createTask(final ExecutorService execDestroy) { return new InitializationTask(execDestroy); } /** - * Returns the result of the background initialization. This method blocks + * Gets the result of the background initialization. This method blocks * until initialization is complete. If the background processing caused a * runtime exception, it is directly thrown by this method. Checked * exceptions, including {@link InterruptedException} are wrapped in a @@ -248,10 +248,10 @@ private Callable<T> createTask(final ExecutorService execDestroy) { * was called causes an {@link IllegalStateException} exception to be * thrown. * - * @return the object produced by this initializer + * @return the object produced by this initializer. * @throws ConcurrentException if a checked exception occurred during - * background processing - * @throws IllegalStateException if {@link #start()} has not been called + * background processing. + * @throws IllegalStateException if {@link #start()} has not been called. */ @Override public T get() throws ConcurrentException { @@ -268,45 +268,44 @@ public T get() throws ConcurrentException { } /** - * Returns the {@link ExecutorService} that is actually used for executing + * Gets the {@link ExecutorService} that is actually used for executing * the background task. This method can be called after {@link #start()} * (before {@code start()} it returns <strong>null</strong>). If an external executor * was set, this is also the active executor. Otherwise this method returns * the temporary executor that was created by this object. * - * @return the {@link ExecutorService} for executing the background task + * @return the {@link ExecutorService} for executing the background task. */ protected final synchronized ExecutorService getActiveExecutor() { return executor; } /** - * Returns the external {@link ExecutorService} to be used by this class. + * Gets the external {@link ExecutorService} to be used by this class. * - * @return the {@link ExecutorService} + * @return the {@link ExecutorService}. */ public final synchronized ExecutorService getExternalExecutor() { return externalExecutor; } /** - * Returns the {@link Future} object that was created when {@link #start()} + * Gets the {@link Future} object that was created when {@link #start()} * was called. Therefore this method can only be called after {@code * start()}. * - * @return the {@link Future} object wrapped by this initializer - * @throws IllegalStateException if {@link #start()} has not been called + * @return the {@link Future} object wrapped by this initializer. + * @throws IllegalStateException if {@link #start()} has not been called. */ public synchronized Future<T> getFuture() { if (future == null) { throw new IllegalStateException("start() must be called first!"); } - return future; } /** - * Returns the number of background tasks to be created for this + * Gets the number of background tasks to be created for this * initializer. This information is evaluated when a temporary {@code * ExecutorService} is created. This base implementation returns 1. Derived * classes that do more complex background processing can override it. This @@ -314,7 +313,7 @@ public synchronized Future<T> getFuture() { * method. Therefore overriding methods should be careful with obtaining * other locks and return as fast as possible. * - * @return the number of background tasks required by this initializer + * @return the number of background tasks required by this initializer. */ protected int getTaskCount() { return 1; @@ -334,15 +333,14 @@ protected Exception getTypedException(final Exception e) { * If initialization failed then the failure will be cached and this will never return * true. * - * @return true if initialization completed successfully, otherwise false + * @return true if initialization completed successfully, otherwise false. * @since 3.14.0 */ @Override public synchronized boolean isInitialized() { - if (future == null || ! future.isDone()) { + if (future == null || !future.isDone()) { return false; } - try { future.get(); return true; @@ -356,7 +354,7 @@ public synchronized boolean isInitialized() { * been started. * * @return a flag whether the {@link #start()} method has already been - * called + * called. */ public synchronized boolean isStarted() { return future != null; @@ -372,17 +370,14 @@ public synchronized boolean isStarted() { * method must be called before {@link #start()}; otherwise an exception is * thrown. * - * @param externalExecutor the {@link ExecutorService} to be used + * @param externalExecutor the {@link ExecutorService} to be used. * @throws IllegalStateException if this initializer has already been - * started + * started. */ - public final synchronized void setExternalExecutor( - final ExecutorService externalExecutor) { + public final synchronized void setExternalExecutor(final ExecutorService externalExecutor) { if (isStarted()) { - throw new IllegalStateException( - "Cannot set ExecutorService after start()!"); + throw new IllegalStateException("Cannot set ExecutorService after start()!"); } - this.externalExecutor = externalExecutor; } @@ -394,14 +389,12 @@ public final synchronized void setExternalExecutor( * successful: only the first invocation of this method returns <strong>true</strong>, * following invocations will return <strong>false</strong>. * - * @return a flag whether the initializer could be started successfully + * @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 + // Determine the executor to use and whether a temporary one has to be created. final ExecutorService tempExec; executor = getExternalExecutor(); if (executor == null) { @@ -409,12 +402,9 @@ public synchronized boolean start() { } else { tempExec = null; } - future = executor.submit(createTask(tempExec)); - return true; } - return false; } }