Synchronized Vs Atomic Vs Volatile:
- Volatile and Atomic is apply only on variable , While Synchronized apply on method.
- Volatile ensure about visibility not atomicity/consistency of object , While other both ensure about visibility and atomicity.
- Volatile variable store in RAM and it’s faster in access but we can’t achive Thread safety or synchronization whitout synchronized keyword.
- Synchronized implemented as synchronized block or synchronized method while both not. We can thread safe multiple line of code with help of synchronized keyword while with both we can’t achieve the same.
- Synchronized can lock the same class object or different class object while both can’t.
Please correct me if anything i missed.