Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / November 2003

Tip: Looking for answers? Try searching our database.

Profiling lock contention

Thread view: 
Jeff Nowakowski - 27 Nov 2003 17:58 GMT
I'm trying to find out how much time is spent waiting for locks in a
program.  Supposedly, there's a way to do this using the built-in
profiler in Sun's JVM:

   java -Xrunhprof:monitor=y

which should write a log file with the following section:

   MONITOR TIME    is a profile of monitor contention obtained by measuring
                   the time spent by a thread waiting to enter a monitor.
                   Entries in this record are TRACEs ranked by the percentage
                   of total monitor contention time and a brief description
                   of the monitor.  The "count" field indicates the number of
                   times the monitor was contended at that TRACE.

However, when I try running this on a sample program that has to wait
5 seconds for a lock, this section is always empty!  I tried using
Sun's 1.4.1_02 SDK as well as IBM's 1.3.1 SDK, on Windows XP
Professional.

Why doesn't this work?  Does it work for anybody?

-Jeff

Here's the program I'm using to test it:

package foo;

import java.util.*;

public class Foo {

   public static void main(String[] args) throws Exception {
       Date start = new Date();
       Foo foo = new Foo();
       Thread thread1 = new Thread(new MyThread(foo), "thread 1");
       Thread thread2 = new Thread(new MyThread(foo), "thread 2");
       thread1.start();
       thread2.start();
       thread1.join();
       thread2.join();
       System.err.println("Done!");
       Date finish = new Date();
       System.err.println("time = " + (finish.getTime() - start.getTime()));
   }

   synchronized void synched() throws Exception {
       System.err.println(
           "Got lock, thread = " + Thread.currentThread().getName());
       Thread.sleep(5000);
   }

   static class MyThread implements Runnable {
       Foo foo;

       public MyThread(Foo foo) {
           this.foo = foo;
       }

       public void run() {
           try {
               System.err.println(
                   "Acquiring lock, thread = "
                       + Thread.currentThread().getName());
               foo.synched();
           } catch (Exception e) {
               e.printStackTrace();
           }
       }

   }
}
Stephen Kellett - 27 Nov 2003 20:24 GMT
>I'm trying to find out how much time is spent waiting for locks in a
>program.

http://www.softwareverify.com

       Java Thread Validator

Currently in beta test. Windows NT/2K/XP platforms.

Stephen
Signature

Stephen Kellett
Object Media Limited    http://www.objmedia.demon.co.uk
RSI Information:        http://www.objmedia.demon.co.uk/rsi.html



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.