how does a thread share data with other thread

Using synchronize locks a variable when it is in use by another thread.

You should use volatile keyword to keep the variable updated among all thread


Using volatile is yet another way (like synchronized, atomic wrapper) of making class thread safe. Thread safe means that a method or class instance can be used by multiple threads at the same time without any problem.

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API