Finding out which thread has interrupted

Discussion in 'Java' started by Manish Jethani, Jan 7, 2004.

  1. Thread th = Thread.currentThread();

    try {
    th.sleep(10000);

    } catch (InterruptedException e) {
    /* I want to know *which* thread interrupted this one. */
    }

    How can I achieve this?

    Tnx.

    Manish

    --
    http://mannu.livejournal.com/
    Manish Jethani, Jan 7, 2004
    #1
    1. Advertising

  2. Manish Jethani <> scribbled the following:
    > Thread th = Thread.currentThread();


    > try {
    > th.sleep(10000);


    > } catch (InterruptedException e) {
    > /* I want to know *which* thread interrupted this one. */
    > }


    > How can I achieve this?


    I think it's pretty much impossible directly. The only way is to have a
    "setInterruptingThread(Thread t)" method in your thread, and then call
    it from the same thread that interrupts it.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "This is a personnel commuter."
    - Train driver in Scientific American
    Joona I Palaste, Jan 7, 2004
    #2
    1. Advertising

  3. Manish Jethani

    FISH Guest

    Manish Jethani <> wrote in message news:<05RKb.4$>...
    > Thread th = Thread.currentThread();
    >
    > try {
    > th.sleep(10000);
    >
    > } catch (InterruptedException e) {
    > /* I want to know *which* thread interrupted this one. */
    > }
    >
    > How can I achieve this?
    >
    > Tnx.
    >
    > Manish



    Create a reference somewhere which the interrupting thread assigns to
    itself immediately before requesting the interrupt. Make sure you cater
    for when two threads attempt to interrupt the same sleeping thread at
    the same time. Either queue them, or discard all attempts after the
    initial one, depending upon your needs.


    -FISH- ><>
    FISH, Jan 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel
    Replies:
    5
    Views:
    602
    Chris Uppal
    Dec 5, 2003
  2. Jakub Moscicki
    Replies:
    2
    Views:
    540
    Jakub Moscicki
    Oct 4, 2003
  3. Andy B
    Replies:
    2
    Views:
    461
    Andy B
    Nov 20, 2008
  4. CinnamonDonkey
    Replies:
    10
    Views:
    2,206
    Tim Golden
    May 15, 2009
  5. Stan Brown
    Replies:
    6
    Views:
    352
    Stan Brown
    Oct 29, 2003
Loading...

Share This Page