I wrote a simple program and noticed that my streams are too fast to run JVisualVM, note which application I want to monitor, connect and watch streams. Then I made them sleep. And they noticed that the tools now report them as sleeping (or almost only about sleep). Although they work. This begs the question: why ?!
new Thread(() -> {
while(true) {
System.out.println("not sleeping");
try {
Thread.sleep(0,1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}, "not sleeping!").start();
This thread should sleep for 1 nanosecond, but look how it told JVisualVM:

After starting for 57 seconds, it reports the operating time of 5s and rests as if sleeping - is it a mistake or is my understanding incorrect?
This is not just JVisualVM:
$ while true; do jstack 8277 | grep -A 2 not; done [% 20:34:27]
"not sleeping!"
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
jstackalso only occasionally reports this stream as RUNNING. I would expect different proportions, so please help me understand.