Wednesday, August 22, 2007

Does Synchronization helps in Managing volatility?

Very often the developers tries to exploit the term Synchronization.
Though Volatile is not a replacement to Synchronization, its just solves the common problems for which the developers tend to use Synchronization. It does nothing more than but just avoids the Compiler to develop the caches for the Volatile Objects, so that the programme can read the Latest value and not the Stale values of an Object.
Synchronization should be used only when the system wants only 1 Thread to execute a particular set of Lines for example Singleton Pattern. Keep in Mind it has performance overheads.
But Synchronization in itself is not a very efficient way. It is being ruled by the key of "All or Nothing" for example in the Synchronized collections like java.util.Hashtable has all the methods as Synchronized even getXXX() methods are also rendered as Thread safe, though it should not be.

No comments: