Hi Rob,
Thanks for your reply.
Rob Prime wrote:
However, if your class has no data of its own (so no static fields)
It doesn't
Rob Prime wrote:
and also does not rely on any external source (like a database)
It doesn't
Rob Prime wrote:
then synchronization is only slowing down your application
I agree
Rob Prime wrote:
In your example, there is no reason methodA and methodB, or even two parallel calls to methodA, should not be allowed to run together.
Absolutely!
Let me then explain why I'm considering synchronizing the methods ...
Please have a look and consider the following
test and output:
Some output if method is not syncronized: (ouch!)
Entering checkIfNull(): a0.09524904426278391
Entering checkIfNull(): b0.23565355167820223
Returning checkIfNull(): b0.23565355167820223
Returning checkIfNull(): a0.09524904426278391
Entering checkIfNull(): b0.7527650118950606
Entering checkIfNull(): a0.8424380146307968
Returning checkIfNull(): b0.7527650118950606
Returning checkIfNull(): a0.8424380146307968
Entering checkIfNull(): b0.42129968213137825
Entering checkIfNull(): a0.6445911951918275
Returning checkIfNull(): a0.6445911951918275
Entering checkIfNull(): a0.9413244263506504
Returning checkIfNull(): b0.42129968213137825
Some output if method is syncronized: (better!)
Entering checkIfNull(): a0.38640850139032057
Returning checkIfNull(): a0.38640850139032057
Entering checkIfNull(): a0.39237764562271704
Returning checkIfNull(): a0.39237764562271704
Entering checkIfNull(): b0.2756009510370935
Returning checkIfNull(): b0.2756009510370935
Entering checkIfNull(): b0.47526899878499873
Returning checkIfNull(): b0.47526899878499873
Entering checkIfNull(): b0.2636586336838118
Returning checkIfNull(): b0.2636586336838118
Hmmmmmmm ... am I missing something?
Thanks!