0

There is a worker class which is executing the task. The code snippet is as follows:

public class Worker{
 executor.execute( new Runnable() {
     public void run() {
         LOG.info("Task starting to execute");
         try {
             Thread.sleep(7000)`
         }catch (InterruptedException)
             LOG.info("Thread Interrupted");
         }
         LOG.info("Task Executed");
     }    

 }

}

Here when i stop worker class when it is in sleep mode, as per my knowledge Interrupted Exception should be thrown. But in reality, it's not. Instead it just stops. Can someone please clarify my misconception. I have seen lots of threads related to this question, still my doubt is not clear

vaibhav.g
  • 729
  • 1
  • 9
  • 28
  • 1
    And how do you "stop" your thread? – Tom Oct 22 '14 at 09:19
  • By clicking on stop button in the IDE – vaibhav.g Oct 22 '14 at 09:20
  • And how should a stopped/terminated JVM catch and log something? – Tom Oct 22 '14 at 09:21
  • Try to edit your question to include a [SSCCE](http://sscce.org/). – afsantos Oct 22 '14 at 09:21
  • @user3162418 The stop button in the IDE stops the entire Java Virtual Machine. Your code abruptly stops, and nothing else runs after clicking it. – afsantos Oct 22 '14 at 09:22
  • Read something about the method `notify`. This will interrupt a thread and causes "him" to throw an `InterruptedException`. – Tom Oct 22 '14 at 09:28
  • @Tom, o.notify() and t.interrupt() are two completely different things. o.notify() will change the state of thread that is blocked in a call to o.wait(), but it will not interrupt the thread. In particular, it will not change the state of a thread that is blocked for any other reason (e.g., in a sleep() call or waiting for I/O). – Solomon Slow Oct 22 '14 at 13:00

0 Answers0