#107 JavaDoc improvements for Async Method Invocation example
This commit is contained in:
parent
ef6a34ef74
commit
8d62156683
@ -3,29 +3,24 @@ package com.iluwatar.async.method.invocation;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This application demonstrates the async method invocation pattern. Key parts of the pattern are
|
||||
* <code>AsyncResult</code> which is an intermediate container for an asynchronously evaluated value,
|
||||
* <code>AsyncCallback</code> which can be provided to be executed on task completion and
|
||||
* <code>AsyncExecutor</code> that manages the execution of the async tasks.
|
||||
* </p>
|
||||
* <p>
|
||||
* The main method shows example flow of async invocations. The main thread starts multiple tasks with
|
||||
* variable durations and then continues its own work. When the main thread has done it's job it collects
|
||||
* the results of the async tasks. Two of the tasks are handled with callbacks, meaning the callbacks are
|
||||
* executed immediately when the tasks complete.
|
||||
* </p>
|
||||
* <p>
|
||||
* Noteworthy difference of thread usage between the async results and callbacks is that the async results
|
||||
* are collected in the main thread but the callbacks are executed within the worker threads. This should be
|
||||
* noted when working with thread pools.
|
||||
* </p>
|
||||
* <p>
|
||||
* Java provides its own implementations of async method invocation pattern. FutureTask, CompletableFuture
|
||||
* and ExecutorService are the real world implementations of this pattern. But due to the nature of parallel
|
||||
* programming, the implementations are not trivial. This example does not take all possible scenarios into
|
||||
* account but rather provides a simple version that helps to understand the pattern.
|
||||
* </p>
|
||||
*
|
||||
* @see AsyncResult
|
||||
* @see AsyncCallback
|
||||
|
@ -2,6 +2,13 @@ package com.iluwatar.async.method.invocation;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
* AsyncCallback interface
|
||||
*
|
||||
* @param <T>
|
||||
*
|
||||
*/
|
||||
public interface AsyncCallback<T> {
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,11 @@ package com.iluwatar.async.method.invocation;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
*
|
||||
* AsyncExecutor interface
|
||||
*
|
||||
*/
|
||||
public interface AsyncExecutor {
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,12 @@ package com.iluwatar.async.method.invocation;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
*
|
||||
* AsyncResult interface
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface AsyncResult<T> {
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,9 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
*
|
||||
* Implementation of async executor that creates a new thread for every task.
|
||||
*
|
||||
*/
|
||||
public class ThreadAsyncExecutor implements AsyncExecutor {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user