Skip to content

Commit cef5087

Browse files
committed
Javadoc
1 parent 6ddfa83 commit cef5087

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

src/main/java/org/apache/commons/lang3/concurrent/BackgroundInitializer.java

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected BackgroundInitializer() {
195195
* scheduled at this service. Otherwise a new temporary {@code
196196
* ExecutorService} is created.
197197
*
198-
* @param exec an external {@link ExecutorService} to be used for task
198+
* @param exec an external {@link ExecutorService} to be used for task.
199199
* execution
200200
*/
201201
protected BackgroundInitializer(final ExecutorService exec) {
@@ -218,7 +218,7 @@ private BackgroundInitializer(final FailableSupplier<T, ConcurrentException> ini
218218
* Creates the {@link ExecutorService} to be used. This method is called if
219219
* no {@link ExecutorService} was provided at construction time.
220220
*
221-
* @return the {@link ExecutorService} to be used
221+
* @return the {@link ExecutorService} to be used.
222222
*/
223223
private ExecutorService createExecutor() {
224224
return Executors.newFixedThreadPool(getTaskCount());
@@ -232,26 +232,26 @@ private ExecutorService createExecutor() {
232232
* at the end of the task.
233233
*
234234
* @param execDestroy the {@link ExecutorService} to be destroyed by the
235-
* task
236-
* @return a task for the background initialization
235+
* task.
236+
* @return a task for the background initialization.
237237
*/
238238
private Callable<T> createTask(final ExecutorService execDestroy) {
239239
return new InitializationTask(execDestroy);
240240
}
241241

242242
/**
243-
* Returns the result of the background initialization. This method blocks
243+
* Gets the result of the background initialization. This method blocks
244244
* until initialization is complete. If the background processing caused a
245245
* runtime exception, it is directly thrown by this method. Checked
246246
* exceptions, including {@link InterruptedException} are wrapped in a
247247
* {@link ConcurrentException}. Calling this method before {@link #start()}
248248
* was called causes an {@link IllegalStateException} exception to be
249249
* thrown.
250250
*
251-
* @return the object produced by this initializer
251+
* @return the object produced by this initializer.
252252
* @throws ConcurrentException if a checked exception occurred during
253-
* background processing
254-
* @throws IllegalStateException if {@link #start()} has not been called
253+
* background processing.
254+
* @throws IllegalStateException if {@link #start()} has not been called.
255255
*/
256256
@Override
257257
public T get() throws ConcurrentException {
@@ -268,53 +268,52 @@ public T get() throws ConcurrentException {
268268
}
269269

270270
/**
271-
* Returns the {@link ExecutorService} that is actually used for executing
271+
* Gets the {@link ExecutorService} that is actually used for executing
272272
* the background task. This method can be called after {@link #start()}
273273
* (before {@code start()} it returns <strong>null</strong>). If an external executor
274274
* was set, this is also the active executor. Otherwise this method returns
275275
* the temporary executor that was created by this object.
276276
*
277-
* @return the {@link ExecutorService} for executing the background task
277+
* @return the {@link ExecutorService} for executing the background task.
278278
*/
279279
protected final synchronized ExecutorService getActiveExecutor() {
280280
return executor;
281281
}
282282

283283
/**
284-
* Returns the external {@link ExecutorService} to be used by this class.
284+
* Gets the external {@link ExecutorService} to be used by this class.
285285
*
286-
* @return the {@link ExecutorService}
286+
* @return the {@link ExecutorService}.
287287
*/
288288
public final synchronized ExecutorService getExternalExecutor() {
289289
return externalExecutor;
290290
}
291291

292292
/**
293-
* Returns the {@link Future} object that was created when {@link #start()}
293+
* Gets the {@link Future} object that was created when {@link #start()}
294294
* was called. Therefore this method can only be called after {@code
295295
* start()}.
296296
*
297-
* @return the {@link Future} object wrapped by this initializer
298-
* @throws IllegalStateException if {@link #start()} has not been called
297+
* @return the {@link Future} object wrapped by this initializer.
298+
* @throws IllegalStateException if {@link #start()} has not been called.
299299
*/
300300
public synchronized Future<T> getFuture() {
301301
if (future == null) {
302302
throw new IllegalStateException("start() must be called first!");
303303
}
304-
305304
return future;
306305
}
307306

308307
/**
309-
* Returns the number of background tasks to be created for this
308+
* Gets the number of background tasks to be created for this
310309
* initializer. This information is evaluated when a temporary {@code
311310
* ExecutorService} is created. This base implementation returns 1. Derived
312311
* classes that do more complex background processing can override it. This
313312
* method is called from a synchronized block by the {@link #start()}
314313
* method. Therefore overriding methods should be careful with obtaining
315314
* other locks and return as fast as possible.
316315
*
317-
* @return the number of background tasks required by this initializer
316+
* @return the number of background tasks required by this initializer.
318317
*/
319318
protected int getTaskCount() {
320319
return 1;
@@ -334,15 +333,14 @@ protected Exception getTypedException(final Exception e) {
334333
* If initialization failed then the failure will be cached and this will never return
335334
* true.
336335
*
337-
* @return true if initialization completed successfully, otherwise false
336+
* @return true if initialization completed successfully, otherwise false.
338337
* @since 3.14.0
339338
*/
340339
@Override
341340
public synchronized boolean isInitialized() {
342-
if (future == null || ! future.isDone()) {
341+
if (future == null || !future.isDone()) {
343342
return false;
344343
}
345-
346344
try {
347345
future.get();
348346
return true;
@@ -356,7 +354,7 @@ public synchronized boolean isInitialized() {
356354
* been started.
357355
*
358356
* @return a flag whether the {@link #start()} method has already been
359-
* called
357+
* called.
360358
*/
361359
public synchronized boolean isStarted() {
362360
return future != null;
@@ -372,17 +370,14 @@ public synchronized boolean isStarted() {
372370
* method must be called before {@link #start()}; otherwise an exception is
373371
* thrown.
374372
*
375-
* @param externalExecutor the {@link ExecutorService} to be used
373+
* @param externalExecutor the {@link ExecutorService} to be used.
376374
* @throws IllegalStateException if this initializer has already been
377-
* started
375+
* started.
378376
*/
379-
public final synchronized void setExternalExecutor(
380-
final ExecutorService externalExecutor) {
377+
public final synchronized void setExternalExecutor(final ExecutorService externalExecutor) {
381378
if (isStarted()) {
382-
throw new IllegalStateException(
383-
"Cannot set ExecutorService after start()!");
379+
throw new IllegalStateException("Cannot set ExecutorService after start()!");
384380
}
385-
386381
this.externalExecutor = externalExecutor;
387382
}
388383

@@ -394,27 +389,22 @@ public final synchronized void setExternalExecutor(
394389
* successful: only the first invocation of this method returns <strong>true</strong>,
395390
* following invocations will return <strong>false</strong>.
396391
*
397-
* @return a flag whether the initializer could be started successfully
392+
* @return a flag whether the initializer could be started successfully.
398393
*/
399394
public synchronized boolean start() {
400395
// Not yet started?
401396
if (!isStarted()) {
402-
403-
// Determine the executor to use and whether a temporary one has to
404-
// be created
397+
// Determine the executor to use and whether a temporary one has to be created.
405398
final ExecutorService tempExec;
406399
executor = getExternalExecutor();
407400
if (executor == null) {
408401
executor = tempExec = createExecutor();
409402
} else {
410403
tempExec = null;
411404
}
412-
413405
future = executor.submit(createTask(tempExec));
414-
415406
return true;
416407
}
417-
418408
return false;
419409
}
420410
}

0 commit comments

Comments
 (0)