이것은 example의 일부 샘플 코드입니다. 내가 알아야 할 것은 call()
이 호출 가능 함수에서 호출 될 때인가? 무엇이 그것을 유발 하는가?Callable 객체를 사용하는 Java Executor에서 call() 메서드가 언제 호출됩니까?
public class CallableExample {
public static class WordLengthCallable
implements Callable {
private String word;
public WordLengthCallable(String word) {
this.word = word;
}
public Integer call() {
return Integer.valueOf(word.length());
}
}
public static void main(String args[]) throws Exception {
ExecutorService pool = Executors.newFixedThreadPool(3);
Set<Future<Integer>> set = new HashSet<Future<Integer>>();
for (String word: args) {
Callable<Integer> callable = new WordLengthCallable(word);
Future<Integer> future = pool.submit(callable); //**DOES THIS CALL call()?**
set.add(future);
}
int sum = 0;
for (Future<Integer> future : set) {
sum += future.get();//**OR DOES THIS CALL call()?**
}
System.out.printf("The sum of lengths is %s%n", sum);
System.exit(sum);
}
}
내가 예측할 수없는 시간에 사용할 수되는 스레드에 대한 문제를 이해하고 구현을 (기본값)을 실행 java.util.concurrent.ThreadPoolExecutor #에있다, 내가해야 '언제 호출 가능 ** 스케줄이 잡히게 될 것인가 **'- 일정이 잡히면 (submit *) * 내가 알아야 할 것이 전부입니다 :) – MalcomTucker
@Malcom : 나는 그것이 더 좋을 것이라고 생각하지 않습니다. 질문은 스케줄링이 프로그램에 보이지 않거 나 관찰 할 수 없기 때문에 나중에 일정이 잡히면 언제 바뀌겠습니까? –