Untitled
unknown
plain_text
2 years ago
994 B
8
Indexable
class Runnable implements MyRunnable{
private String threadName;
public MyRunnable (String threadName);
this.threadName=threadName;
}
public void run(){
System.out.println("Thread"+threadName+"is Starting!");
try{
Thread.sleep(500);
}
catch(InterruptedException e){
System.out.println("Thread"+threadName+"was Interuppeted");
}
}
public class thread{
public static void main(String[]args){
System.out.println("Main Thread is Starting");
Thread thread1= new Thread (new MyRunnable("Thread1"));
Thread thread2=new Thread(new MyRunnable("Thread2"));
Thread thread3= new Thread(new MyRunnable("Thread3"));
thread1.start();
thread2.start();
thread3.start();
try{
thread1.join();
thread2.join();
thread3.join();
}
catch(InterruptedException e){
System.out.println("The Main Thread was Interuppeted");
}
System.out.println("Main Thread is existing!");
}
}Editor is loading...
Leave a Comment