synchronized object set to null
java, multithreading, synchronization
Solution
This will almost certainly break the synchronization abstraction -- I wouldn't be confident that `thread2` will see the change immediately. You should never change the reference of the object you're synchronizing on, much less set it to `null`, which will cause a `NullPointerException` on any further attempts to synchronize on it.
Problem
I have two threads `Thread1` and `Thread2` ``` //Within Thread1 synchronized(obj1) { obj1 = null; } //Within Thread2 synchronized(obj1) { do something } ``` If jvm first executes thread1 and sets obj1 to null, then will thread2 see that change immediately or will it take time and jvm could still run the thread2 synchronized block since obj1 is not yet null?