Multi thread synchronization


import java.io.*;
import java.util.*;
import java.lang.*;

class MultiThread1 extends Thread
{
public static void main(String args[])
{
Runnable r1=new Runnable()
{
synchronized public void run()
{
for(int i=1;i<=10;i++)
System.out.println(“2*”+i+” = “+(2*i));
}
};

Runnable r2=new Runnable()
{
synchronized public void run()
{

for(int i=1;i<=10;i++)
{
int count=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
count=1;
}
if(count==0)
{
System.out.println(“Prime No: “+i);
}
}
}
};
Runnable r3=new Runnable()
{
synchronized public void run()
{
int next=0,prev=1,temp;
System.out.println(“Fibonacci : “+0+””);
System.out.println(“Fibonacci : “+1+””);
for(int i=0;i<10;i++)
{
temp=next+prev;
System.out.println(“Fibonacci : “+temp+””);
next=prev;
prev=temp;
}
}
};
Thread t1=new Thread(r1);
Thread t2=new Thread(r2);
Thread t3=new Thread(r3);
t1.start();
t2.start();
t3.start();
}
}