lorraine batol
lorraine batol

Reputation: 6281

What will happen if you call interrupt() on a sleeping thread?

I have a thread, and on run() I call sleep(). What will happen if I interrupt this thread?

MyThread extends Thread{
    public void run(){
          try{
             sleep(1000000);
          } catch(InterruptedException e) {//}
    }    
}

I want to clarify the following:

Upvotes: 2

Views: 1427

Answers (1)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136112

1) Thread.interrupt API: Interrupting a thread that is not alive need not have any effect.

2) In your example the interrupted thread will enter catch block then leave run method and terminate

Upvotes: 3

Related Questions