3

I am trying to reduce the lock contention on a particular code-path in my application. To identify code with high lock contention, I connect YourKit to my application and use the "Monitor" tab and see acquiring which locks have caused the thread I care about to block. My eventual aim is to have no red dots for this thread in the "Thread" tab in YK GUI.

Often the contention arises from read/read locking using an intrinsic lock, so those can be improved by using a ReentrantLock instead of the intrinsic lock. Indeed when I tried this, YourKit reported lower contention. Is that information reliable? Does YourKit report usage of ReentrantLock's correctly?

I am using YourKit 8.0.24 on Solaris 10 with Sun 1.6u18 32-bit JVM.

Binil Thomas
  • 13,699
  • 10
  • 57
  • 70

2 Answers2

0

Looks like YourKit, as of now, does not report ReentrantLocks as blocked in the "Thread" tab.

Binil Thomas
  • 13,699
  • 10
  • 57
  • 70
-2

Instead of following a locking-approach try to design your application be lockfree. With volatile variables and the classes in java.util.concurrent you can often write algorithms that are lockfree and therefore have no lock contention.

Tobias P.
  • 4,537
  • 2
  • 29
  • 36
  • 2
    Yes i know, not easy but will result in much better performance. The book "Java Concurrency in practice" is really good to learn more aspects of mostly lockfree programming. – Tobias P. Jun 15 '10 at 15:47