Tuesday, 25 September 2018

Thread.join() Method in Multi Threading java


class MyThread extends Thread{
public void run(){
// print child thread 5 times here
for(int i =0 ; i<=5 ; i++){
System.out.println("child Thread....");
}
}
}

//main method class which is main thread here
class JoinDemo{
public static void main(String args[]){
// this is main thread
// print main thread here

// create thread
MyThread t = new MyThread();
t.start(); // start child thread here

try{
t.join();// pause main thread here and after complete t resume current thread
}catch(Exception e){
System.out.println("Exception caught "+e);
}


for(int i =0 ; i<=5 ; i++){
System.out.println(" Main Thread....");
}

}
}

JTable Hide and Show in Java Swing