Java Thread Methods

 package com.company;



class MyThr extends Thread{

public void run(){
System.out.println("Thank you " + this.getName());
}
}
class MyThr2 extends Thread{

public void run(){
try {
Thread.sleep(455);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Thank you " + this.getName());
}
}

public class tuts {
public static void main(String[] args) {
MyThr t1 = new MyThr();
MyThr t2 = new MyThr();
t1.start();
try{
t1.join();
}
catch(Exception e){
System.out.println(e);
}

t2.start();
}
}

Comments

Popular posts from this blog

Creating a Thread by Extending Thread class

Constructors from Thread class in Java