Using static and non static synchronized method for protecting
shared resource is another Java mistake we are going to discuss
in this part of our series “learning from mistakes in Java”. In
last article we have seen why double and float should not be
used for monetary calculation , In this tutorial we will find
out why using static and non static synchronized method together
for protecting same shared resource is not advisable. I have
seen some times Java programmer mix static synchronized method
and instance synchronized method to protect same shared
resource. They either don't know or failed to realize that
static synchronized and non static synchronized method lock on
two different object which breaks purpose of synchronizing
shared resource as two thread can concurrently execute these two
method breaking mutual exclusive access, which can corrupt
status of mutable object or even cause subtle race condition in
Java or even more horrible deadlock in java. Static and non
static synchronized method Java For