«
Prev
»
Next
Difference between synchronized and volatile:
| synchronized | volatile |
| Synchronized block applies only to object. | volatile keyword can be applied to Object or primitive types. |
| Synchronized block does not work on null. Attempting to synchronize on a null object will throw a NullPointerException. | volatile variables can be null. |
| synchronized blocks other threads while one thread is accessing the block. | volatile does not block any threads. |
| synchronization occurs when you enter a synchronized block. | synchronization occurs when a volatile variable is accessed. |
More Related questions...
Comments & Discussions