java - 没有执行器的Java Callable async
问题描述
我环顾四周,有很多例子,但找不到直接的答案。请看下面的代码。我不想将我的可调用任务提交给执行者以获得未来。我只想称它为原始的。所以我直接调用 .call() 会阻塞当前线程吗?我的意思是它会阻止通话吗?谢谢
public class CustomCallable implements Callable<Long> {
private long number;
public CustomCallable(final long number) {
this.number = number;
}
@Override
public Long call() throws Exception {
//do something
return number;
}
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
Callable<Long> cCallable = new CustomCallable(i);
cCallable.call();//The question is: is this going to block until it finishes the current call, or continue spinning others. Is the loop going to continue without waiting the previous call? or just continue until it reaches <10?
}
}
解决方案
推荐阅读
- wcf - WCF 代理的生命周期
- rest - Graph API:将呼叫转移到呼叫队列
- regex - 突出显示的值的正则表达式是什么?
- select - SELECT max(date) 返回最新记录但数据错误
- oracle - 在oracle中用count和sum连接三个表
- postman - 邮递员不为 PaymentsOS 工作(授权不工作)
- html - 创建具有较少边框的表格
- python - 对 Pandas 列中的元素应用函数,分组到另一列
- unity3d - Text Mesh Pro UGUI 对象在播放模式下消失,Unity 版本 2019.3.5fl 个人版
- javascript - 我可以将对象的所有键声明为变量吗?