Home Tutorial Java Core Java Thread destroy

 
 

Java Thread destroy
Posted on: November 8, 2012 at 12:00 AM
Advertisement
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)
Advertisement

Related Tags for Java Thread destroy :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 8, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com