1 Star 0 Fork 2.8K

韵律浮尘/asyncTool

forked from 京东零售/asyncTool 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Test.java 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
wuweifeng10 提交于 2020-05-18 18:26 +08:00 . 调整
package depend;
import com.jd.platform.async.executor.Async;
import com.jd.platform.async.worker.WorkResult;
import com.jd.platform.async.wrapper.WorkerWrapper;
import java.util.concurrent.ExecutionException;
/**
* 后面请求依赖于前面请求的执行结果
* @author wuweifeng wrote on 2019-12-26
* @version 1.0
*/
public class Test {
public static void main(String[] args) throws ExecutionException, InterruptedException {
DeWorker w = new DeWorker();
DeWorker1 w1 = new DeWorker1();
DeWorker2 w2 = new DeWorker2();
WorkerWrapper<WorkResult<User>, String> workerWrapper2 = new WorkerWrapper.Builder<WorkResult<User>, String>()
.worker(w2)
.callback(w2)
.id("third")
.build();
WorkerWrapper<WorkResult<User>, User> workerWrapper1 = new WorkerWrapper.Builder<WorkResult<User>, User>()
.worker(w1)
.callback(w1)
.id("second")
.next(workerWrapper2)
.build();
WorkerWrapper<String, User> workerWrapper = new WorkerWrapper.Builder<String, User>()
.worker(w)
.param("0")
.id("first")
.next(workerWrapper1, true)
.callback(w)
.build();
//虽然尚未执行,但是也可以先取得结果的引用,作为下一个任务的入参。V1.2前写法,需要手工给
//V1.3后,不用给wrapper setParam了,直接在worker的action里自行根据id获取即可.参考dependnew包下代码
WorkResult<User> result = workerWrapper.getWorkResult();
WorkResult<User> result1 = workerWrapper1.getWorkResult();
workerWrapper1.setParam(result);
workerWrapper2.setParam(result1);
Async.beginWork(3500, workerWrapper);
System.out.println(workerWrapper2.getWorkResult());
Async.shutDown();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/JavaLead/asyncTool.git
git@gitee.com:JavaLead/asyncTool.git
JavaLead
asyncTool
asyncTool
master

搜索帮助