Last active
February 3, 2023 10:56
-
-
Save yashb042/cca8e41b7e40238e22f69eb998719d33 to your computer and use it in GitHub Desktop.
This file contains 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
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