NullPointerException on synchronized statement
<p>I tried to synchronize on an object in my code below:</p>

<pre><code>public void myMethod() {
    synchronized (globalObj) {
        //Do something here
    }
}
</code></pre>

<p>The code is executed in one thread. The issue is that, another thread may set 'globalObj' to null. Then, 'synchronized (globalObj)' will throw NullPointerxception when 'globalObj' has been set to null by other threads.</p>

<p>What's the best practice to synchronize on an object so NullPointerException will not be thrown?</p>

<p>Thanks.</p>
