Consider the following code:
class ThreadJoinTest{
public static void main(String[] arguments){
TimeUnit unit;
final Thread taskThread = new Thread(task);
taskThread.start();
taskThread.join(unit.millis(timeout));
}
}
So, when the main thread executes a line taskThread.join()with a timeout value, will the main thread give taskThreadenough time to complete its task? Is this the main goal of the join method?
What happens if:
taskThread terminates before timeout?- What happens if a timeout is reached but has
taskThreadnot completed execution? Does he get the opportunity taskThreadto complete his task or not? - How does the main thread know that the connection has returned because it
taskThreadended normally or because a timeout has been reached?
source
share