by Dinesh Thakur Category: Multithreading

 

class ImplementingRunnableInterface implements Runnable

          {
              Thread t;
              ImplementingRunnableInterface(String n)
             {
                 t=new Thread(this,n);
                 System.out.println("Thread is :"+t);
                 t.start();
             }
                     public void run()
                        {
                       try
                          {
                            for(int i=1;i<=5;i++)
                           {
                              System.out.println(t.getName()+":"+i);
                              t.sleep(500);
                           }
                               }
                                     catch(InterruptedException e)
                                    {
                                    System.out.println(t.getName()+" is Interrupted");
                                    }
                         }
           }
                     class TwoThreads
                          {
                          public static void main(String args[])
                           {
                                ImplementingRunnableInterface k1=new ImplementingRunnableInterface("Java Thread");
                                ImplementingRunnableInterface k2=new ImplementingRunnableInterface("Advanced Java Thread");
                           }
                          }

Two Threads in Java by Implementing Runnable Interface



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular 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.



Related Articles