ThreadDeath error - calling stop method on thread throws ThreadDeath error in java

Calling stop method on thread throws ThreadDeath error. It’s important to note ThreadDeath is error not exception
/** Copyright (c), AnkitMittal */
public class ThreadDeathDemo {
   public static void main(String[] args) throws InterruptedException {
          Thread thread1 = new Thread("thread-1") {
                 public void run() {
                       try {
                                            + " has started");
                              //calling stop method throws ThreadDeath error.

                       } catch (ThreadDeath e) {
                                            + " has died");
thread-1 has started
thread-1 has died

Must know :
ThreadDeath is an error which application must not try to catch but it is normal condition.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
//start paginationJs //end paginationJs