~Sumit<br /><a href="http://faq.javaranch.com/view?ScjpWallOfFame" target="_blank">SCJP Wall of Fame</a>
SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
Question is how it works like this when locked on System.out? If I change lock to be on this ouptputs will get mixed interweaving One's and Two's print statement.
Now, if I keep lock on 'this' only and start both threads with 't1' as runnable object, I will get nice output of either all One's first or all Two's first. This makes somewhat sense to me, as I am starting two threads with same runnable object, and locking on 'this' makes them properly synchronized. Please correct me if this is not correct assumption.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Question is how it works like this when locked on System.out?
SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
Now, if I keep lock on 'this' only and start both threads with 't1' as runnable object, I will get nice output of either all One's first or all Two's first.
Regards,<br />Kamal<br /> <br />Life is nothing but a competition to be the criminal rather than the victim -Bertrand Russell
I mean System.out is static lock
SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
~Sumit<br /><a href="http://faq.javaranch.com/view?ScjpWallOfFame" target="_blank">SCJP Wall of Fame</a>
Regards,<br />Kamal<br /> <br />Life is nothing but a competition to be the criminal rather than the victim -Bertrand Russell
Originally posted by kamal shah:
Ramesh,
Yes you are right.By static lock my mean was Class lock.
Sumit,
Yes,If we will use same t1 for both threads,lock on 'this' will work absolutely fine.
By static lock you mean a class lock.
But just to make it clear, you aren't saying that a System.out is locking a class because its a static member, right? Because it's locking the object there in System.out.
If we wanted to lock a class we need to put a NameOfClass.class.
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Regards,<br />Kamal<br /> <br />Life is nothing but a competition to be the criminal rather than the victim -Bertrand Russell
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|