Results 1 to 3 of 3
  1. #1
    naik_amit is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default interrupt to thread

    We can interrupt a thread if it is sleeping.
    But what if i interrupt a thread which is runing?

    Does this defers the execution the thread?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by naik_amit View Post
    We can interrupt a thread if it is sleeping.
    But what if i interrupt a thread which is runing?

    Does this defers the execution the thread?
    Ripped from that API documentation for the Thread class:

    Quote Originally Posted by API Thread
    If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.

    If this thread is blocked in an I/O operation upon an interruptible channel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException.

    If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.

    If none of the previous conditions hold then this thread's interrupt status will be set.

    Interrupting a thread that is not alive need not have any effect.
    In particular the second to last sentence is important ...

    kind regards,

    Jos

  3. #3
    naik_amit is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default

    thanks.
    It means if thread is not doing any i/o operations then there is no harm.

Similar Threads

  1. interrupt sleeping thread by mouse action
    By BigBear in forum AWT / Swing
    Replies: 5
    Last Post: 08-12-2010, 10:10 PM
  2. interrupt a jdbc connection thread
    By ko_aung in forum Threads and Synchronization
    Replies: 5
    Last Post: 04-12-2010, 08:04 PM
  3. Replies: 2
    Last Post: 03-19-2010, 08:24 AM
  4. Anyone know how to interrupt a process forcibly?
    By 2potatocakes in forum Advanced Java
    Replies: 3
    Last Post: 04-05-2009, 06:29 PM
  5. Replies: 0
    Last Post: 01-28-2008, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •