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
Post a Comment