CPU time is the time a program or method spends executing on the CPU. Compare it with total execution time when investigating latency: substantial CPU time suggests the code is working, while a long execution time with little CPU time suggests it is waiting. section 7.1
Start with sampling to find where execution time is spent. Expand the execution stack and focus first on the methods taking the longest. If a method uses substantial CPU time, consider whether its algorithm can be improved. If it mostly waits, investigate what it is waiting for. section 7.1 section 7.4
Waiting for an HTTP response
A sampled call to HttpURLConnection.getResponseCode() takes about five seconds but reports zero CPU time. The method is waiting for an HTTP response rather than doing CPU work, so changing its algorithm would not address the observed delay. section 7.1
Investigating a possible lock
A method reports about 700 ms of CPU self time and 4,903 ms of total execution self time. The gap suggests waiting within the method; a thread lock is a likely cause, but sampling alone does not identify it. In VisualVM, use the Locks button on the Profiler tab to investigate further. section 9.2
Figure 9.6 The method doesn’t wait for something, but instead it waits for itself. We observe that its self-execution time is longer than the total CPU time, which usually means that the thread is locked. The thread could have been blocked by another thread.
Compare CPU and execution self time as a clue to thread blocking. section 9.2
Sampling provides the big picture, but it may not reveal the cause of waiting. Use more detailed profiling when needed, focusing on the relevant packages or classes because profiling is more resource-consuming. section 9.2 section 7.4




