For some reason I am confused over the following:
Assume that I have Thread A
that absolutely needs to execute after Thread B
has completed its processing.
A way to do this would be by Thread A
joining Thread B
.
Trivial example:
public class MainThread {
public static void main(String[] args){
Thread b = new Thread (new SomeRunnable(args[0]));
b.start();
try {
b.join();
} catch(InteruptedException e) {
}
// Go on with processing
}
}
My question is the following: What is the proper way to handle the exception in such a case?
In various example I have seen, even in text-books, the exception is ignored.
So if Thread A
needs to be sure that Thread B
is completely finished before proceding, if I end up in the catch due to an exception, can it be the case that Thread B
may still actually be runnable/running? So what is the best way to handle this exception?