DynamicAttachDemo

Dynamic Attach Demo

This demo script is part of the NetBeans World Tour 2008 session #8, Integrated Profiling Tools. Refer to the top-level demo scripts page for additional information.

Main Points to Hit

  • With JDK 6 you can attach the profiler to an application that is already running. No special JVM command line flags are necessary when you start that application.
  • Dynamic attach works even if you do not have a NetBeans project defined for the application.

Prerequisities

  • JDK6
  • NetBeans 6.0 M10 (or higher) running on Java 6

Setup

  1. Create the AnagramGame sample project
  2. Open the AnagramGame project
  3. Clean and Build the AnagramGame project. Note that in the Output window the IDE will provide you with the correct command line syntax for running the AnagramGame outside the IDE. Save that command line string; for example: java -jar "/home/projects/standard/AnagramGame/dist/anagrams.jar"
  4. Close the AnagramGame project.

Gotchas

  • The profiler cannot find the running processes on Win XP running over Parellels on Mac OS X.

Demo Steps

  1. Open a command line window and paste in the command line that will start AnagramGame (from the Setup steps). Suggested Comment (SC): "I am going to start the AnagramGame from the command line and run it using JDK6. Notice there are no special command line flags being used."
  2. Press Enter to start the AnagramGame.
  3. Go back to the IDE. Select Profile > Attach Profiler.
  4. At the top of the Attach dialog is a drop-down list labelled Attach to: make sure the <External application> entry is selected.
  5. Click the Monitor button on the left.
  6. Click the Attach button in the lower right.
  7. If this is your first time using Dynamic Attach, the Attach Wizard will start. Set the Target Type to Application, the Attach method to local and the Attach invocation to Dynamic (JDK 1.6). At this point you can press Finish. I'm not sure what the last page of the wizard is for: "If you haven't integrated the Java Application for profiling yet, click the Next button to continue with Java Application Integration".
  8. The Select Process dialog is displayed. SC: "The profiler looks for JVMs on this system."
  9. Select the AnagramGame entry and then click OK.
  10. The profiler attaches and displays the telemetry views. SC: "We're in! Note: we're doing this without even having a NetBeans project open. The downside on that, of course, is that we will lose some of the nice features, such as 'Go To Source.' If you have a NetBeans project defined and open, then you can select it as the beginning of the attach process (instead of <External application>)."
  11. Select Profile > Detach. Click the No button in the dialog so that AnagramGame will continue to run. SC: "And now we have detached. The application keeps on going."  :-)
  12. Switch to the AnagramGame to show that it is still running.

Notes:

  1. Dynamic attach only works if the application being profiled is running on JDK6 and the NetBeans IDE itself is running on JDK6.
  2. JDK5 does not support dynamic attach
  3. In NetBeans 5.0 and 5.5 the profiler supported dynamic attach to JDK 1.4.2, but only if you ran your application on a special hacked version of the JVM that was available on the netbeans.org web site. That hacked version of the JVM is not supported by NetBeans 6.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo