For Java Web Start applications and applets, you can use most of techniques available to debug and profile standalone applications, except you will need to use the attach mechanism instead of direct launch.
Note: Both plugin and Java Web Start will spawn additional java
or javaw
processes that will actually run the JVM executing the application or applet. You need to attach to those processes to be able to collect information about your applet. For example, if you want to get a memory dump of your applet, then first you need to figure out the process id for the java
process executing the PluginMain
class. For example, use theThe jps Utility utility from the JDK and then use The jmap Utility to get a memory dump.
The following are development tips for debugging applets.
Debug Java applets and Web Start applications:
Just as with standalone Java applications, any JPDA-based debugger can be used to debug your applet or Web Start application; for example, see The jdb Utilityor the NetBeans debugger.
You will need to enable the JDWP agent for the JVM running your application and specify the port number. Once the JVM is started, you can use your favorite IDE or tools to attach to it.
For details on how to pass arguments to the JVM running applet or Java Web Start application, see Pass Parameters to the JRE. Example 16-1 shows how you can pass details to the Java Web Start application from the command line.
Example 16-1 Command-line Option to Debug Java Web Start Application
bash$ javaws -J-agentlib:jdwp=transport=dt_socket,address=4000,server=y,suspend=y http://acme.com/my/webstart.jnlp
This instructs the agent to suspend after the JVM is initialized and wait for a debugger to connect on port 4000. Please consult jdpa
documentation for invocation options.
For FAQs on Web Start Applications, see Java Web Start.
Profile Java applets and Java Web Start applications:
When you profile a standalone Java application, your favorite IDE is likely to be using the JVMTI agent to collect details on program execution. You can do the same for applets and Java Web Start applications but you may need to configure the JVMTI agent explicitly by passing the -agentpath
option to the JVM as shown in Example 16-2. For details on how to pass options to the JVM, see Pass Parameters to the JRE.
Example 16-2 Configure JVMTI Agent
set _JPI_VM_OPTIONS="-agentpath:C:\Tools\NetBeans\profiler\lib\deployed\jdk16\windows\profilerinterface.dll=C:\Tools\NetBeans\profiler\lib,5140"
Now launch your browser. The NetBeans profile agent is enabled for any applet you will be running in this browser session. You can use NetBeans IDE to attach to the java
process. Please consult your profiler documentation for exact details on what agent to use and how to configure it.
Debug memory leaks:
See Troubleshoot Memory Leaks for any techniques available for standalone applications on the process running your applet or application. For example, use jmap
to obtain a heap dump, VisualVM or jconsole
to observe threads, or pass -XX:+HeapDumpOnOutOfMemoryError
to the JVM (see Pass Parameters to the JRE) to get a memory dump on error. Use the jps
utility to find the process id for the process running your application.