My thoughts on Volatile keyword in Java: Volatile keyword in Java

Commentary

  • Volatile keyword in Java
  • I don’t know why but I like java now. It is more verbose, means lesser chance of messing things up, no assumptions while writing. Thought that could mean there are more bugs since if we write more, it can mean more area for edit. But I like learning things, and Java is a bit challenging coming from Python.
  • The volatile keyword makes the variable read from the actual CPU instead of the cache. It brodcasts that the value has been changed and the thread has to invalidate the cache and later when it requires it, it fetches it fresh from the CPU.