To use those classes instead of the ones from the JDK you need to prepend your jar containing them into the bootclasspath. getAbsolutePath ()) BufferedWriter writer = new BufferedWriter ( new FileWriter ( statsFile )) try It means in those cases there is a contention with another thread which already holds the current lock.įile statsFile = new File ( "./ReentrantLockStats.txt" ) System. I have identified in the code where the lock fails to be acquired. I copied the JDK classes and kept them in the same package. The plan wasn’t to create any wrapper around them or any subtype, but to intercept the actual classes. The goal was to profile existing code using j.u.c.Locks. The technique is simple and I will describe it below. I have also found an article describing jucProfiler, a tool created by an IBM team.īefore finding those 2 last tools, I made a very light and quick j.u.c.Lock profiler on my own. It helps to identify which locks are effectively in contention. Profile information seems precise with callstacks. I suppose it uses instrumentation to insert callbacks when j.u.c.Lock classes are used. However, another profiler which is able to profile j.u.c.Lock exists: JProfiler. Hence, no special information about them. It is part of the JDK classes like any regular library. Here, this is trickier: j.u.c.Lock is not handled by the JVM. Profilers like YourKit exploit this information to provide contention profiling.Īzul Systems provides with their Zing JVM a tool named ZVision to also profile the synchronized blocks: With those, JVM provides, via JVMTI, some events that can be used by native agents to get information about synchronized blocks: MonitorContendedEnter & MonitorContentedEntered. The first ones are directly handled by the JVM with the help of a specific byte code ( monitorenter & monitorexit). Those with synchronized blocks, and those which use. You see in this Java world there are two kinds of locks. Measuring this contention will help us to pinpoint which locks need to be improved. Locks become a bottleneck if more than one thread tries to acquire them and needs to wait for a release. Before rushing into this specific approach, it would be interesting to determine which part of your locking code would really benefit from this. However it is sometimes more difficult to use or to integrate into your existing code. Lock-Free structures offer an alternative to your lock usage. Locks is one of the major bottleneck in scalability for your code.
0 Comments
Leave a Reply. |