首页 > 解决方案 > 没有执行器的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? 
    }
}

标签: javaasynchronousexecutorservicecallableexecutor

解决方案


推荐阅读