I've a Java application, which is not fast enough as I expected. I've done a lot of searches of how to improve it, but not lucky.
Now I'm reviewing the code, and found there are a lot of synchronized
keyword in the code. I'm thinking if they took too much time on waiting the locks.
Is there any tool to check how much time they cost? Thus I can find a better solution if they do cost too much time.
I was going to suggest the Thread Monitor feature of jvisualvm and, while looking for a screen shot, ran into this blogpost: Detecting Thread Contentions. It's way better than just a screenshot :).
But here it is anyway: (image credit: aforementioned blog post)
A good profiler will be able to pinpoint the methods that are causing slowness it may not be related to the synchronization at all. Also looking at the state of the threads in profiler may reveal if there is too much of waiting going on because of the synchronization. In any case unless the synchronized keyword is being used without reason it may be counter productive to remove it for the sake of performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With