logo

Java 스레드 destroy() 메소드

그만큼 파괴하다() 스레드 클래스의 메소드는 스레드 그룹과 모든 하위 그룹을 파괴하는 데 사용됩니다. 스레드 그룹은 비어 있어야 하며, 이는 스레드 그룹에 있던 모든 스레드가 중지되었음을 나타냅니다.

통사론

 public void destroy() 

반품

어떤 값도 반환하지 않습니다.

예외

IllegalThreadStateException: 이 예외는 스레드 그룹이 비어 있지 않거나 스레드 그룹이 이미 삭제된 경우 발생합니다.

보안예외: 현재 스레드가 이 스레드 그룹을 수정할 수 없는 경우.

 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;>