Thank you very much this very elementairy and basic explanation Henry!.
Henry Wong wrote:Basically, at the core level, there are two threading terms to be concerned with -- the mutex and the condition variable.
A. The mutex is a mutually exclusive lock, which is a fancy way of saying "something that is guaranteed to only have one owner". To guarantee that a thread is the only one operating on some piece of data, it should grab a mutex assigned for it, do the work, and release the mutex. The mutex will do the work of enforcing the guarantee that there will only be one owner, and hence, guarantee that only one thread will work on the data....... In Java speak, the mutex is implemented via the synchronization keyword.
Jim Hoglund wrote:Good explanation but here is one adjustment. The JVM does not stop other threads.
2 - The JVM switches from "Multi-threading" (of all threads running in memory at the same time) turns into "Single threading" (execution only of the SynchronizedCounter. object/thread)
2 - The JVM executes only the SynchronizedCounter. object/thread, and put all other threads "on hold" until the SynchronizedCounter. object/thread is ready
Jim Hoglund wrote:Ronald : My observation was that the JVM does not switch to a different mode. Other threads remain running, time-sliced by the JVM. In fact, your synchronized method can be swapped out, and another thread can run the same method. This is not a problem as long as the second thread operates on a different object.
Again, threads do not stop or start based on synchronized code. Methods are not locked; only objects are locked.
Jim ... ...