Sun Certified Java Programmer (SCJP)..... One would safely assume that a person who has cleared SCJP at least understands java as a language, its constructs keywords.
Q: What does synchronized keyword do when added as modified of a method?
A: It prevents two threads to execute method at a same time.
Hmm, answer is acceptable. So, whats the buzz about it being hilarious ..... read on ...
Q: So how does JVM ensure that only one thread executes synchronized method a time ?
A: Well locks are acquired against method.
Q: Okay, locks are acquired on methods !!!!! right ?
A: Yes
Now this fellow is trapped !!!!
Q: If in a class there are two synchronized methods. Can two separate threads execute those two synchronized methods at the same time as both will have lock of separate methods will be acquired ?
A: Absolutely
Disclaimer: Although I am SCJP, I wasn't answering these questions in this manner. Please do not confuse me and interviewee.
Thursday, April 1, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment