• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • Piet Souris
  • Jj Roberts
  • fred rosenberger


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?

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%)
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic