224. Observing and monitoring virtual threads
Observing and monitoring virtual threads can be done in several ways. First, we can use Java Flight Recorder (JFR) – we introduced this tool in Chapter 6, Problem 143.
Using JFR
Among its reach list of events, JFR can monitor and record the following events related to virtual threads:
jdk.VirtualThreadStart
– this event is recorded when a virtual thread starts (by default, it is disabled)jdk.VirtualThreadEnd
– this event is recorded when a virtual thread ends (by default, it is disabled)jdk.VirtualThreadPinned
– this event is recorded when a virtual thread is parked while pinned (by default, it is enabled with a threshold of 20 ms)jdk.VirtualThreadSubmitFailed
– this event is recorded if a virtual thread cannot be started or unparked (by default, it is enabled)
You can find all the JFR events at https://sap.github.io/SapMachine/jfrevents/.
We start...