Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

---Thread Example in Java for multithreading ---





package Fab;
class Fab {
  public synchronized void displayFab(int num)
  {
int a=-1,b=1,c;
for(int i=1;i<=num;i++)
       {
         c=a+b;
         System.out.println(c);
        try
         {
             Thread.sleep(1000);
        }
         catch(InterruptedException ex)
        {

        }
         a=b;
         b=c;
       }
    }
 }

class Thread11 extends Thread
{
     Fab f;
     int num;
    Thread11(Fab f,int num)
    {
     this.f=f;
     this.num=num;
     }
     public void run()
     {
     f.displayFab(num);
     }
     public static void main(String args[])
     {
     Fab f = new Fab();
     Thread11 obj = new Thread11(f,5);
    obj.start();

     Thread11 obj1 = new Thread11(f,10);
     obj1.start();
    }
}


Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post