I have a doubt regarding "Synchronized" in JAVA....
class A extends Thread
{
String name;
int no;
public synchronized void accept()
{ BufferedReader br= new BufferedReader(new InputStreamReader(System.in);
System.out.println("name");
Thread.sleep(1000);
name=br.readLine();
System.out.printl("no");
Thread.sleep(1000);
no= Integer.parseInt(br.readLine());
}
public void display()
{
System.out.println("name:"+name);
Thread.sleep(1000);
System.out.println("no:"+no);
Thread.sleep(1000);
}
public void run()
{
accept();
display();
}
}
class B
{
public static void main(String args[])
{
A a1= new A();
A a2= new A();
a1.start();
a2.start();
}
Here accept() should work as a single Thread method and display should work
as a multi Thread method. But both the methods are working as multi Thread
methods.
what is the problem?
--
with regards ...kiran
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en