VisualVM has two separate tabs for sampling and profiling. What is the difference between sampling and profiling in VisualVM?
Asked
Active
Viewed 2.2k times
1 Answers
190
Sampling
means taking lots of thread dumps and analyzing stack traces.
This is usually faster, does not require runtime changes in your bytecode (which may break it), but is also less accurate.
Profiling
means instrumenting your classes and methods, so they "report" whenever they are run. This is more accurate, as it counts every invocation of instrumented method, not only those caught when the dump is done. However instrumentation means that the bytecode of your classes is changed, and this may break your program. Actually, for that reason, using profiling on large application servers (like JBoss, or WebLogic) often causes everything to die or hang.

Edgar Asatryan
- 687
- 9
- 13

npe
- 15,395
- 1
- 56
- 55
-
4Would it mean that profiling is more accurate than sampling, but it would take more resources ? – Parag Aug 26 '12 at 12:33
-
14I have found that Sampling is more than accurate enough every time I've used it for pinpointing the bad performing methods. I personally never use profiling. – Marquez Feb 06 '17 at 16:30