W
W
WTFAYD2017-08-13 17:21:16
Java
WTFAYD, 2017-08-13 17:21:16

How are Thread.join() and InterruptedException related?

Tell me, why do you need to put a catch block with InterruptedException to call Thread.join()? I can't get the connection. For example, for the Thread.sleep() method, this is logical - the catch block will indicate actions if the sleep is interrupted. Why Thread.join()?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pazukdev, 2021-01-20
@pazukdev

1. You need to put a catch block because the join() method throws InterruptedException
2. The join method throws an InterruptedException if the thread calling it is interrupted:

Thread.currentThread().interrupt();
t.join(); // will throw InterruptedException

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question