Hi,
Synchronization comes in pictures if you want to access same object using multiple thread. So that data should be in consistent state. Here in your example we are creating two different threads and they have there own objects so they will execute without going in block state.

On 6/18/2010 1:28 PM, ravi kiran wrote:
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


--
With Regards,
Shiv Shankar

--
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

Reply via email to