try {
thread2.join();
}
catch(InterruptedException e) {
System.out.println("Exception caught : " + e);
}

It works.