Hi Sir...
This is Naseem here. I have one confusion in synchronization concept.
I read that in synchronization if one
thread is accessing ny synchronized method, no other thread can access that method at that time. I am getting that same from my code.
In main method I created 100 different threads.
Now in threads's run() method i hav a synchronized method
test() which just print int value from 0 to 9.
public void run(){test();}
public synchronized void test(){
for(int k=0;k<=9;k++){
System.out.print(k);
}
System.out.print("");
}
In one run its output coming is
0123456789
01234567890000000000111111111122222222223333333333444444444455555555566666666567
777777677888888788999999899.....etc
Since test method is synchronized, so only one thread must enter in test method at a time so what I think is the output should come like this:
First thread prints : 0123456789
Second thread prints: 0123456789
Third thread prints : 0123456789
Fourth thread prints: 0123456789
.
.
etc.(Total 100 value for 100 thread)
means in every SOP value should be 0123456789.
Plz help...
Thanks & Regards
Naseem Khan