I have a method in Java that call several other methods. This method is being called from several threads, in a fixed thread pool. The number of workers is the same as the number of available processors (cores).
public void query() {
method1();
method2();
}
When I profile the program execution using VisualVM the times of method1()
and method2()
times are very short, but query()
self-time is very long. But the method has no other code apart from the two calls. There might be synchronization inside method1()
and method2()
, but nothing obvious in code that I have control of.
When I reduce the number of workers in the pool to 1, this self-time is almost gone. Both single-threaded and multi-threaded execution times of the whole program are almost the same. I think it means that my method query()
is waiting for something.
There are no deadlocks, the execution finishes fine. The two methods method1()
and method2()
call a lot of other things including library classes in obfuscated jars, so it is not easy for me to debug it. However the query()
method is called directly from the worker threads, using java.util.concurrent.ExecutorService
.