Thanks Mike,
Originally posted by Mike Gershman:
There are probably fancy ways, but I would put these statements like these at the beginning and end of each method or synchronized block:
System.out.println( "method3 requests lock " + this );
System.out.println( "method3 holds lock " + this );
System.out.println( "method3 releases lock " + this );
If you need to know which this is which instance, add an informative println with this to the constructor:
System.out.println( "Salary object for employee " + empNo + " is " + this );
If there are many lines of output, write to a file and examine the end of the file for the deadlock. If you do this, be sure to use a PrintWriter or PrintStream with autoflush true in the constructor or use flush() after every write so you get the last lines of output.
[ February 01, 2005: Message edited by: Mike Gershman ]
Your reply is very helpful. I am wondering how to write a utility class so that I need not hardcode all "System.out" manually. I want this utility class to automatically track/record the retrieval and release of locks. Do you have any good ideas?
regards,
George