What does the keyword "synchronize" mean in java. When do you use it? What are the disadvantages of synchronization?
Synchronize is used when u want to make ur methods thread safe. The disadvantage of synchronise is it will end up in slowing down the program. Also if not handled properly it will end up in dead lock.1. Only use (and minimize it's use)synchronization when writing multithreaded code as there is a speed (up to five to six time slower, depending on the execution time of the synchronized/nonsynchronized method ) cost associated with its use.2. In case of syncronized method modifier, the byte code generated is the exact same as non-syncronized method. The only difference is that a flag called ACC_SYNCRONIZED property flag in method's method_info structure is set if the syncronized method modifier is present.3. Also, syncronized keyword can make the code larger in size if used in the body of the method as bytecode for monitorenter/monitorexit is generated in addition to any exception handling.
-
Interview Candidate
- Aug 28th, 2004
- 1
- 3677
Showing Answers 1 - 1 of 1 Answers
Related Answered Questions
Related Open Questions
What does the keyword "synchronize" mean in java. When do you use it? What are the disadvantages of synchronization?
Related Answered Questions
Related Open Questions