Skip to content

VisualVM launcher error

I’m trying to use the Eclipse VisualVM launcher. It seems pretty nice, except that it seems to spawn an instance if VisualVM too late to do any profiling of my application. My application finishes execution before the profiler is even initialized; once it starts up, an error window pops up, saying: cannot open requested application. It then shows VM running Eclipse (labeled “org.eclipse.equinox.launcher.Main”). How can I get it to wait for my application and do proper profiling?

Answer

I know that problem. The only poor man’s solution I always came up with is:

  1. Set a breakpoint in your source code
  2. Start your program in debug mode
  3. Connect the profiler
  4. Let the program continue

It just takes a bit time for VisualVM to inject the profiling agent into your VM and I am pretty sure that it allows only remote profiling.

As an alternative you could use YourKit, it can profile your application from the very start. This way the profiling agent is injected on VM startup:

java -agentpath:c:yourkityjpagent.dll FooClass

I am curious why VisualVM does not offer this option, since its technically possible. Anyway I think the debug trick is a good solution from within Eclipse, unless you are also interested in the class loading etc.