You are here:   HomeJava ProgrammingMultithreadingJava Example for Join Thread
by Dinesh Thakur Category: Multithreading

 

class FourThreads extends Thread

                     {
                        FourThreads(String n)
                      {
                         super(n);
                         System.out.println("Thread is :"+getName());
                      }
                         public void run()
                           {
                           try
                             {
                               for(int i=1;i<=3;i++)
                                   {
                                      System.out.println(getName()+":"+i);
                                      sleep(200);
                                   }
                                     }
                                             catch(InterruptedException e)
                                      {
                                          System.out.println(getName()+"is Interrupted");
                                      }
                             }
                     }
                             class FourThreadsJavaExample
                           {
                           public static void main(String args[])
                             {
                                FourThreads t1=new FourThreads("First Thread");
                                FourThreads t2=new FourThreads("Second Thread");
                                FourThreads t3=new FourThreads("Third Thread");
                                FourThreads t4=new FourThreads("Fourth Thread");
                                t1.start();
                                t2.start();
                                t3.start();
                                t4.start();
                             }
                            }

Four Threads in Java Example



Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article