मैं ThreadPoolExecutor#afterExecute()
विधि में कार्यकर्ता धागे द्वारा फेंकने वाले निष्पादन को संभालना चाहता हूं।ThreadPoolExecutor के बाद अपवाद() में अपवाद क्यों शून्य है?
public class MyExecutor extends ThreadPoolExecutor {
public static void main(String[] args) {
MyExecutor threadPool = new MyExecutor();
Task<Object> task = new Task<>();
threadPool.submit(task);
}
public MyExecutor() {
super(4, 20, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>(4000));
}
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
System.out.println("in afterExecute()");
if (t != null) {
System.out.println("exception thrown: " + t.getMessage());
} else {
System.out.println("t == null");
}
}
private static class Task<V> implements Callable<V> {
@Override
public V call() throws Exception {
System.out.println("in call()");
throw new SQLException("testing..");
}
}
}
अगर मैं कोड चल रहा आउटपुट प्राप्त:
in call()
in afterExecute()
t == null
पैरामीटर Throwable t
null
afterExecute()
में क्यों है वर्तमान में मैं इस कोड है? यह SQLException
उदाहरण नहीं होना चाहिए?
इसे साफ़ करने के लिए धन्यवाद। तो सभी चेक अपवादों को ThreadPoolExecutor द्वारा निगलने जा रहे हैं? और सभी अपवाद हैंडलिंग कॉलबल # कॉल() में किया जाना चाहिए? –
@ potato300 मेरा संपादन देखें, आपके विशिष्ट उदाहरण में कुछ और चल रहा है (जिसे मैंने पहले नहीं देखा था) – Tunaki