When should you synchronize? Apply Brian’s Rule of Synchronization
If you are writing a variable that might next be read by another thread, or reading a
variable that might have last been written by another thread, you must use
synchronization, and further, both the reader and the writer must synchronize using the
same monitor lock.
If you have more than one method in your class that deals with the critical data, you must
synchronize all relevant methods. If you synchronize only one of the methods, then the
others are free to ignore the object lock and can be called with impunity. This is an important
point: Every method that accesses a critical shared resource must be synchronized or it
won’t work right.