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