hello,
can anyone help me with this pls,
class Vijay
{
public synchronized void viju(int a)
{
int aa=a;
for (int i=0;i<10;i++)
{
System.out.println("ito the method the value is"+aa);
try{
Thread.currentThread().sleep(500);
}catch(Exception e)
{
System.out.println("interrupted");
}
}//end of for.
}
public static void main(
String []as)
{
final Vijay v=new Vijay();// an object of type Vijay
Runnable r=new Runnable(){
public void run()
{
v.viju(10);
}
};
Thread t=new Thread(r);
t.start();
final Vijay v1=new Vijay();//another object of type Vijay
Runnable r1=new Runnable(){
public void run()
{
v1.viju(20);
}
};
Thread tt=new Thread(r1);
tt.start();
}
}
*** my question is.
how do i make use of the synchronized method,What i want is only one thread should access the method at one time(even with two different objects)...is this possible.