Interrupted when connected to other streams

How should I handle InterruptedExceptionwhen connecting to other threads, assuming that I actually do not expect an interruption, and there is no reasonable thing? Just swallow the exception?

try
{
    t.join();
    u.join();
}
catch (InterruptedException e)
{
    // should not happen
}

Or should I put each one joinseparately try/catch, so if it InterruptedExeptionhappens when connecting t, at least it ugets a chance to join?

try
{
    t.join();
}
catch (InterruptedException e)
{
    // should not happen
}
try
{
    u.join();
}
catch (InterruptedException e)
{
    // should not happen
}

Or should I defend exceptions in the loop, so am I finally joining both threads, even if some kind of evil guy is trying to interrupt me?

while (true)
{
    try
    {
        t.join();
        break;
    }
    catch (InterruptedException e)
    {
        // no way, Jose!
    }
}
while (true)
{
    try
    {
        u.join();
        break;
    }
    catch (InterruptedException e)
    {
        // no way, Jose!
    }
}

On the side of the note, is there a case where InterruptedExeptionit doesn't make my code look ugly? :)

+3
source share
1

- , , , , - - RuntimeException (, IllegalStateException). , , , , - - .

, , , .

+2

All Articles