Skip to content

Instantly share code, notes, and snippets.

@yashb042
Last active February 3, 2023 10:56
Show Gist options
  • Save yashb042/cca8e41b7e40238e22f69eb998719d33 to your computer and use it in GitHub Desktop.
Save yashb042/cca8e41b7e40238e22f69eb998719d33 to your computer and use it in GitHub Desktop.
void runVirtual() throws Exception {
for (; ; ) {
long start = System.currentTimeMillis();
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 100_000_0; i++) {
executor.submit(() -> {
callExternalService();
return null;
});
}
}
long end = System.currentTimeMillis();
System.out.println(end - start + " ms");
}
}
private void callExternalService() throws InterruptedException {
Thread.sleep(Duration.ofMillis(1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment