Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class thread implements Runnable
- {Thread t;
- String name;
- thread(String tname)
- {
- name =tname;
- t=new Thread(this,name);
- t.start();
- System.out.println("thread "+name+": "+t);
- }
- public void run(){
- try{
- for(int i=5;i>0;i--)
- {
- System.out.println("thread "+name+": "+i);
- Thread.sleep(1000);
- }
- }catch(InterruptedException e)
- {
- System.out.println("error ");
- }
- }
- }
- public class join {
- public static void main(String argv[])
- {
- thread ob1=new thread("one");
- thread ob2=new thread("two");
- thread ob3=new thread("three");
- System.out.println("thread "+ob1.t +" is "+ob1.t.isAlive());
- System.out.println("thread "+ob2.t +" is "+ob2.t.isAlive());
- System.out.println("thread "+ob3.t +" is "+ob3.t.isAlive());
- try{
- System.out.println("waiting for thread to finish");
- ob1.t.join();
- ob2.t.join();
- ob3.t.join();
- }catch(InterruptedException e)
- {
- System.out.println("error in main");
- }
- System.out.println("thread "+ob1.t +" is "+ob1.t.isAlive());
- System.out.println("thread "+ob2.t +" is "+ob2.t.isAlive());
- System.out.println("thread "+ob3.t +" is "+ob3.t.isAlive());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment