best regards,<br />Steven<br />SCJP, SCEA
Rob
SCJP 1.4
best regards,<br />Steven<br />SCJP, SCEA
Rob
SCJP 1.4
best regards,<br />Steven<br />SCJP, SCEA
newly SCJP2 <img src="tongue.gif" border="0">
Great thanks,<br />Luco Zhao
best regards,<br />Steven<br />SCJP, SCEA
best regards,<br />Steven<br />SCJP, SCEA
newly SCJP2 <img src="tongue.gif" border="0">
best regards,<br />Steven<br />SCJP, SCEA
Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank">here</a> to see an example.
Originally posted by Francisco A Guimaraes:
...if the class implemented Runnable instead of extending Thread, would the syncronization make a difference?
Originally posted by Steven Sun:
I think the key is here:
for synchronized method:
only the datas that accessed by the method will be locked,not means that the second thread cant invoke the same method.Situation can be thus:the two thread both can get chance to run,when thread1 get it,it prints something but not all,then thread2 get the chance to run,because the method didnt lock any datas,so thread2 can easily continue,so it also print.
may be :
Thread One is running... at i=0
Thread One is running... at i=1
Thread One is running... at i=2
Thread One is running... at i=3
Thread One is running... at i=4
Thread One is running... at i=5
Thread One is running... at i=6
Thread One is running... at i=7
Thread Two is running... at i=0
Thread Two is running... at i=1
Thread Two is running... at i=2
Thread Two is running... at i=3
Thread Two is running... at i=4
Thread Two is running... at i=5
Thread Two is running... at i=6
Thread Two is running... at i=7
Thread Two is running... at i=8
Thread Two is running... at i=9
Thread One is running... at i=8
Thread One is running... at i=9
i think the synchronized object also the same reason.
if i am wrong,correct me
newly SCJP2 <img src="tongue.gif" border="0">
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|