Skip to content

Instantly share code, notes, and snippets.

@tomi-1995
Created May 15, 2024 04:57
Show Gist options
  • Save tomi-1995/2354ced3b6349f2f8911641c2f49d9f2 to your computer and use it in GitHub Desktop.
Save tomi-1995/2354ced3b6349f2f8911641c2f49d9f2 to your computer and use it in GitHub Desktop.
202405_note_codes
// 従来のスレッド
Thread.ofPlatform().start(() -> {
sleep(5);
log("Platform Thread");
}).join();
// 仮想スレッド
Thread.ofVirtual().start(() -> {
sleep(5);
log("Virtual Thread");
}).join();
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 1000000; i++) {
executor.submit(() -> {
sleep(5);
log("Virtual Thread");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment