• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

InterruptedException

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per the java doc "java.lang.InterruptedException" is defined as:


Thrown when a thread is waiting, sleeping, or otherwise paused for a long time and another thread interrupts it using the interrupt method in class Thread.



When I was checking for its usage I found it in join() and sleep() method of thread class and wait() method of Object class.

Why not Yield() method of thread?

Thanks,
Praveen
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
join( ) , wait( ) and sleep( ) send a thread to a waiting state and not a runnable state
whereas yield( ) sends a thread to a runnable state and not in
a waiting state

when you call the interrupt method on that thread , an InterruptedException
is thrown if and only if the thread is not in a runnable state

that is why methods such as join( ) , wait( ) and sleep( ) throw
an InterruptedException

On the other hand when interrupt is called on a thread which
is running or in a runnable state its "interrupt status" is set
(which can be verified using the isInterrupted method in the Thread class)

Setting the "interrupt status" does not affect the state of the
thread in any way and it contines to be in running or runnable state

Hope i hav cleared u r doubt ,

santhosh sharma (scjp 1.4 100%)
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic