• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q 28 of examlab practice test 3

 
geeta vemula
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Answer is prints Ex-B and then excetion is thrown.

But my doubt is why there is no effect of the following two statements of main?
doDelay(100);
a.interrupt();
Why is not throwing Interrupted exception?
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
geeta vemula wrote:
But my doubt is why there is no effect of the following two statements of main?
doDelay(100);
a.interrupt();
Why is not throwing Interrupted exception?


doDelay(100); What are you expecting from this line.

a.interrupt(); will cause nothing, as thread reference is pointed by t. If you call t.interrupt, then you could expect its effect.
As no thread is running by reference a, so no effect of a.interrupt.
 
Abhishek Bhat
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But Class a itself is a thread...then why wud it not have any effect....

even though the Thread creation method used is the one that is used when the class implements Runnable it wont overshadow the fact that a is a thread and any method in the thread class invoked on t can also be invoked on a ..Please correct me if am wrong...
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here a.start() is not called, so thread a is not running, class a' run() is just the target of thread t, actual thread that is running in its own stack is threat referenced by t.
 
Abhishek Bhat
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Oh Punit..sorry buddy...i dint see that..i just saw that the class extends Thread and put up a dumb show...really sorry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic