logo

طريقة تدمير خيط جافا ().

ال هدم() يتم استخدام طريقة فئة الخيط لتدمير مجموعة الخيط وجميع مجموعاتها الفرعية. يجب أن تكون مجموعة سلاسل الرسائل فارغة، مما يشير إلى أن جميع سلاسل الرسائل التي كانت موجودة في مجموعة سلاسل الرسائل قد توقفت منذ ذلك الحين.

بناء الجملة

 public void destroy() 

يعود

ولا يقوم بإرجاع أي قيمة.

استثناء

استثناء غير قانوني لـThreadState: يظهر هذا الاستثناء إذا لم تكن مجموعة سلاسل الرسائل فارغة أو إذا تم إتلاف مجموعة سلاسل الرسائل بالفعل.

سلسلة جافا إلى كثافة العمليات

استثناء أمان: إذا لم يتمكن مؤشر الترابط الحالي من تعديل مجموعة سلاسل الرسائل هذه.

مثال

 public class JavaDestroyExp extends Thread { JavaDestroyExp(String threadname, ThreadGroup tg) { super(tg, threadname); start(); } public void run() { for (int i = 0; i <2; i++) { try thread.sleep(10); } catch (interruptedexception ex) system.out.println('exception encounterted');} system.out.println(thread.currentthread().getname() + ' finished executing'); public static void main(string arg[]) throws interruptedexception, securityexception creating a threadgroup g1="new" threadgroup('parent thread'); child for parent g2="new" threadgroup(g1, 'child thread javadestroyexp t1="new" javadestroyexp('thread-1', g1); another t2="new" javadestroyexp('thread-2', block until other is t1.join(); t2.join(); destroying g2.destroy(); system.out.println(g2.getname() destroyed'); g1.destroy(); system.out.println(g1.getname() < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> Thread-1 finished executing Thread-2 finished executing child thread destroyed Parent thread destroyed </pre> <br></2;>