Limitations of synchronized keyword
1. Doesn't allow concurrent read, which can potentially limit scalability.
To overcome this limitation, use lock stripping and use different locks for reading and writing.
java.util.concurrent.locks.ReentrantReadWriteLock provides readymade implementation of ReadWriteLock.
2. It can be used to control access of shared object within the same JVM only.
Synchronized access to a shared file system or database on more than one JVM, the synchronized keyword is not at all sufficient.
There is a need to implement a kind of global lock for that.
3. It incurs performance cost. It is very slow and can degrade performance.
It should be used when it absolutely required and must use synchronized block for synchronizing critical section only.
4. It could result in deadlock or starvation while accessing by multiple thread if synchronization is not correctly implemented.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.