• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

relation between interrupt status and sleep method

 
shankara me
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
--->My doubt Is on relation ship between sleep method and interrupt status flag.
--->I am asking this doubt based on below two programmes.
--->In programme1, I have called sleep method with out clearing interrupt status .Then InterruptedException was thrown.
--->In programme2 ,I have called sleep method after clearing interrupt status flag using interrupted method.Then InterruptedException was not thrown.
Is there any relation ship between sleep method and interrupt status flag?
Does sleep method throws Interrupted exception based on interrupt status flag?
---------------------------------------------------------------
Programme1:

Output:
10
interrupted
12
interrupted
14
interrupted
16
interrupted
18
interrupted
20
Interrupted
---------------------------------------------------------------
Programme2:

output:
10
12
14
16
18
20
---------------------------------------------------------------

 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shankara me wrote:Hi !
--->My doubt Is on relation ship between sleep method and interrupt status flag.
--->I am asking this doubt based on below two programmes.
--->In programme1, I have called sleep method with out clearing interrupt status .Then InterruptedException was thrown.
--->In programme2 ,I have called sleep method after clearing interrupt status flag using interrupted method.Then InterruptedException was not thrown.
Is there any relation ship between sleep method and interrupt status flag?
Does sleep method throws Interrupted exception based on interrupt status flag?
---------------------------------------------------------------
Programme1:

Output:
10
interrupted
12
interrupted
14
interrupted
16
interrupted
18
interrupted
20
Interrupted
---------------------------------------------------------------
Programme2:

output:
10
12
14
16
18
20
---------------------------------------------------------------




That's how it works. If the thread is interrupted during the sleep() method (or there is an interruption that hasn't been handled yet), then the method will clear the interrupt flag, and throw the InterruptedException.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic