Home Tutorial Java Core Java Thread destroy

 
 

Java Thread destroy
Posted on: November 8, 2012 at 12:00 AM
In this tutorial, we are using Thread.destroy() method to destroy the thread.

Java Thread destroy

In this tutorial, we are using Thread.destroy() method to destroy the thread.

Thread destroy() :

Thread class provides destroy method to destroy the thread. In general, Thread.destroy() is dangerous and not implemented. The basic idea is to kill the thread and break its monitor locks. But if it is done at the middle of any process then the deadlock condition occur. So usually we don't use this method.

public void destroy() : This method destroy your thread without any cleanup. The locked monitor remains lock. Implementation of this method is not done.

Example :

class ThreadDestroy implements Runnable{
	public static void main(String args[]){
	    Thread thread=new Thread();
	    thread.start();
	    try {
	      //destroy  thread without any cleanup.
	      thread.destroy();
	    } catch (Throwable e) {
	      System.out.println("destroy() throws "+e+"("+e.getMessage()+")");
	    }
	  }

	@Override
	public void run() {
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
				e.printStackTrace();
		}
		
	}
}

Output :

destroy() throws java.lang.NoSuchMethodError(null)

Related Tags for Java Thread destroy :


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.