.NET में एग्रीगेट एक्सेप्शन क्लास आपको अपवाद फेंकने की अनुमति देता है जिसमें कई अपवाद हैं।.NET से AggregateException के जावा समतुल्य क्या है?
उदाहरण के लिए, यदि आप समांतर में कई कार्यों को चलाते हैं तो आप एक समेकित अपवाद फेंकना चाहते हैं और उनमें से कुछ अपवादों के साथ विफल रहे हैं।
क्या जावा के बराबर वर्ग है?
विशिष्ट मामले मैं में उपयोग करना चाहते हैं:
public static void runMultipleThenJoin(Runnable... jobs) {
final List<Exception> errors = new Vector<Exception>();
try {
//create exception-handling thread jobs for each job
List<Thread> threads = new ArrayList<Thread>();
for (final Runnable job : jobs)
threads.add(new Thread(new Runnable() {public void run() {
try {
job.run();
} catch (Exception ex) {
errors.add(ex);
}
}}));
//start all
for (Thread t : threads)
t.start();
//join all
for (Thread t : threads)
t.join();
} catch (InterruptedException ex) {
//no way to recover from this situation
throw new RuntimeException(ex);
}
if (errors.size() > 0)
throw new AggregateException(errors);
}
मैं एक के बारे में पता नहीं कर रहा हूँ के लिए बनाया गया था कुछ इसी तरह करना होगा। हालांकि, मैंने कभी भी एक की तलाश नहीं की है। – Powerlord