Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
QZero_0
java-design-patterns
提交
8d621566
J
java-design-patterns
项目概览
QZero_0
/
java-design-patterns
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
java-design-patterns
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8d621566
编写于
8月 18, 2015
作者:
I
Ilkka Seppala
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#107 JavaDoc improvements for Async Method Invocation example
上级
ef6a34ef
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
20 addition
and
5 deletion
+20
-5
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java
...c/main/java/com/iluwatar/async/method/invocation/App.java
+0
-5
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncCallback.java
...a/com/iluwatar/async/method/invocation/AsyncCallback.java
+7
-0
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java
...a/com/iluwatar/async/method/invocation/AsyncExecutor.java
+5
-0
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java
...ava/com/iluwatar/async/method/invocation/AsyncResult.java
+6
-0
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java
...iluwatar/async/method/invocation/ThreadAsyncExecutor.java
+2
-0
未找到文件。
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java
浏览文件 @
8d621566
...
...
@@ -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
...
...
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncCallback.java
浏览文件 @
8d621566
...
...
@@ -2,6 +2,13 @@ package com.iluwatar.async.method.invocation;
import
java.util.Optional
;
/**
*
* AsyncCallback interface
*
* @param <T>
*
*/
public
interface
AsyncCallback
<
T
>
{
/**
...
...
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncExecutor.java
浏览文件 @
8d621566
...
...
@@ -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
{
/**
...
...
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java
浏览文件 @
8d621566
...
...
@@ -2,6 +2,12 @@ package com.iluwatar.async.method.invocation;
import
java.util.concurrent.ExecutionException
;
/**
*
* AsyncResult interface
*
* @param <T>
*/
public
interface
AsyncResult
<
T
>
{
/**
...
...
async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java
浏览文件 @
8d621566
...
...
@@ -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
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录