यह example से कुछ नमूना कोड है। मुझे क्या पता होना चाहिए कि 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);
}
}
मैं धागे में पूर्वानुमान लगाना कठिन समय उपलब्ध बनने के बारे में मुद्दे को समझने, मैं होना चाहिए पूछा गया कि 'कब कॉल करने योग्य ** ** निर्धारित होगा **' - जब तक यह * सबमिट() * पर निर्धारित हो जाता है तब मुझे यह जानने की ज़रूरत है :) – MalcomTucker
@ मैल्कॉम: मुझे नहीं लगता कि यह बेहतर होगा प्रश्न, चूंकि शेड्यूलिंग प्रोग्राम के लिए दृश्यमान/देखने योग्य नहीं है, इसलिए बाद में निर्धारित होने पर क्या बदल जाएगा? –