Shekar Chandu wrote:
So Java came up with synchronized keyword
which applied on a method ,it becomes protected from multiple threads.
Well, in the world of threading, the issue of data inconsistency (that causes problems) is a universal issue. And the various different threading environments come up with different tools, that when applied correctly, solves this data inconsistency/corruption issue.
Of those tools, many of them are similar -- such as Mutex locks, Semaphores, Reader-Writer locks, Condition Variables, CAS operations, etc. Java (at least starting with Java 5) is one of those environments that provides you access to *all* of the tools listed...
Anyway, with Java, the synchronized keyword, enables the concept of a Mutex lock. The locks are mutually exclusive. Only one thread may own the lock at any one time. So, if you apply them correctly to methods, only one method (of the methods using the same mutex) may be called at any one time. And ideally, if applied correctly, this will lead to not having corrupted data.
Henry