Annotation Interface VirtualThreadUnit


@Target(TYPE) @Retention(RUNTIME) @ExtendWith(VirtualThreadExtension.class) public @interface VirtualThreadUnit
Extends the test case to detect pinned carrier thread.

Implementation notes: current implementation uses JFR under the hood, with two consequences:
  1. This test won’t work on JVM without JFR support, e.g. OpenJ9.
  2. Each test that uses this annotation is several seconds longer than versions without it.
This annotation uses JFR recording to detect pinning and analyze when a specific event is fired. Unfortunately, to ensure no events are missed, the test must ensure the JFR recording is on and off. It fires a mock event and wait until it read it. Due to JFR recording API limitations, it takes a lot of time to do these loops as there are many file reads. This adds several seconds to start and to stop to each test with pinned carrier thread detection enabled; and this additional work is mandatory to avoid missing event.
This behaviour is not part of API and may change in future version.