الإيقاف ومعالجة الأخطاء
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
stop pools cleanly and not lose failures.
الموضوعات المخطط لها
shutdown()stops accepting tasks and lets queued ones finish;shutdownNow()interrupts workers.- Pattern:
shutdown(),awaitTermination(timeout), thenshutdownNow(). - Non-daemon pool threads keep the JVM alive if you never shut down.
- Tasks given to
executethat throw print to the thread's uncaught handler; withsubmitthe exception hides inside theFutureuntilget(). - Always log or collect failures.
تفاصيل المخطط المبدئي
عرض عملي
pool.shutdown();
if (!pool.awaitTermination(30, TimeUnit.SECONDS)) pool.shutdownNow();اختبر فهمك
Why can a failed submit task go unnoticed?
أظهر الإجابة
The exception is stored in the Future; nobody called get().
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.