Last updated June 09, 2009 23:08, by Roman Ondruska
Feedicon  

Deadlock Detection in NetBeans---Project Deadlock

Description

The Deadlock project contains a simple application demonstrating NetBeans ability to check for deadlocks. Sometimes (especially in large apps) a deadlock is reported by users from time to time, but it is hard to reproduce it (and thus hard to fix). In the Deadlock demo, you will reproduce a deadlock and the debugger will detect it for you.

Requirements: NB 6.5 or better

Intro

Have a look what this little app does...

  1. Start the application Deadlock without debugger control (~ right-click the project node in the Projects window and choose Run).

Application will create two extra threads ('MyThread1' and 'MyThread2') that do almost nothing valuable ;-) and finish in a moment. See the output:

 run:
 Application started
 MyThread2 successfully finished.
 MyThread1 successfully finished

Both two threads successfully finished without any deadlock.

Deadlock Reproduction & Detection

Let's play with the app to reproduce and detect the deadlock...

  1. Expand the myapplication package and open Thread1.java and Thread2.java in the source editor.
  2. Toggle one line breakpoint in Thread1.java at line 20 and another in Thread2.java at line 20.
  3. Right-click the Deadlock project in the Projects window and choose Debug. The main method will run the two threads, and both threads will be suspended at one of the breakpoints. You can see the threads suspended by the breakpoints in the Debugging window.
  4. In the Debugging Window, resume the suspended threads (MyThread1 and MyThread2) by clicking the Resume buttons to the right of the suspended threads in the Debugging window.
  5. Since the threads are not finishing the execution, it is possible they are involved in a deadlock. Go to the Main Menu -> Debug and choose 'Check for Deadlock' action. The deadlock will be detected and the Debugging view provides you with the details. Note that the involved threads are emphasized in red color.

In this demo we have proved that the application is not deadlock-safe and its synchronization should be fixed.

  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close