When to attach
There are two main reasons for attaching the Debugger to a process or JVM:
- You anticipate a problem at a particular point in your program, and you do not want to
step through the program or set breakpoints. In this situation, you can run your program,
and during a program pause shortly before the anticipated failure (for example, while the
program is waiting for keyboard input), you attach the Debugger. You can then provide the
input, and debug from that point on.
- You are developing or maintaining a program that hangs sporadically, and you want to
find out why it is hanging. In this situation, you can attach the Debugger, and look for
infinite loops or other problems that might be causing your program to hang.
You can
also use the debug on demand feature to invoke the Debugger when an application running on
your system throws an exception that is not handled. Debug on demand is not
available when debugging interpreted Java programs.
Note: You can
attach the Debugger to an already running program or a running Java Virtual Machine
(JVM)
where an error or failure has occurred.


Attaching to a local running
process
Attaching to a remote running
process
Attaching to a running Java Virtual Machine
Enabling
and disabling debug on demand