Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debugging Java synchronization

Tags:

java

Is there any mechanism within the Eclipse debugging environment to see the state of synchronization locks held and processes waiting?

like image 718
ddyer Avatar asked May 03 '10 09:05

ddyer


People also ask

What is the problem with synchronization in Java?

Synchronization can result in hold-wait deadlock where two threads each have the lock of an object, and are trying to acquire the lock of the other thread's object. Synchronization must also be global for a class, and an easy mistake to make is to forget to synchronize a method.

What is Java debugging?

Debugging is the routine process of locating and removing bugs, errors or abnormalities from programs. It's a must have skill for any Java developer because it helps to find subtle bug that are not visible during code reviews or that only happens when a specific condition occurs.

What is Java synchronization?

Synchronization in java is the capability to control the access of multiple threads to any shared resource. In the Multithreading concept, multiple threads try to access the shared resources at a time to produce inconsistent results. The synchronization is necessary for reliable communication between threads.


2 Answers

You can show the state of object monitors in Eclipse's debugger. You can find a short, clear tutorial here. For each thread, Eclipse can show you the monitors the thread owns and those it is waiting for.

Update 2020-01-20: The link above no longer works. Here's a link to cached version on the Internet Archive.

like image 141
T . Avatar answered Sep 19 '22 17:09

T .


As suggested here you could (if you run the Sun JVM) perform the following steps:

  1. launch jconsole or jvisualvm (both present in the bin-directory of your JDK-installation,
  2. attach to the process you suspect has locked up
  3. go to the Threads pane. There is a "Detect Deadlock" button
like image 23
aioobe Avatar answered Sep 21 '22 17:09

aioobe