---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++)
{
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();
}
}
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
POST Answer of Questions and ASK to Doubt