Created
July 25, 2023 11:10
-
-
Save franz1981/5e333f3b230fc3513492b95fcae6a1ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package red.hat.puzzles.concurrent; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.infra.Blackhole; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.Executor; | |
import java.util.concurrent.Executors; | |
@State(Scope.Benchmark) | |
@Measurement(iterations = 5, time = 1) | |
@Warmup(iterations = 10, time = 1) | |
@Fork(value = 2, jvmArgsAppend = "--enable-preview") | |
public class VirtualThreadCreation { | |
@Param("10") | |
int work; | |
@Param("1024") | |
int tasks; | |
Executor executor; | |
@Setup | |
public void init() { | |
executor = Executors.newVirtualThreadPerTaskExecutor(); | |
} | |
@Benchmark | |
public void submitWork() throws InterruptedException { | |
var done = new CountDownLatch(tasks); | |
for (int i = 0; i < tasks; i++) { | |
executor.execute(() -> { | |
Blackhole.consumeCPU(work); | |
done.countDown(); | |
}); | |
} | |
done.await(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment