Created
May 17, 2020 22:18
-
-
Save AlexeySoshin/3c1f56671a5a91f55cdc1fb550bc585c 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
var threads = new ArrayList<Thread>(); | |
var cores = 10; | |
for (var i = 0; i < cores; i++) { | |
var t = Thread.startVirtualThread(() -> { | |
var bestUUID = ""; | |
for (var j = 0; j < 1_000_000; j++) { | |
var currentUUID = UUID.randomUUID().toString(); | |
if (currentUUID.compareTo(bestUUID) > 0) { | |
bestUUID = currentUUID; | |
} | |
} | |
System.out.println("Best slow UUID is " + bestUUID); | |
}); | |
threads.add(t); | |
} | |
for (var i = 0; i < cores; i++) { | |
var t = Thread.startVirtualThread(() -> { | |
var bestUUID = UUID.randomUUID().toString(); | |
System.out.println("Best fast UUID is " + bestUUID); | |
}); | |
threads.add(t); | |
} | |
for (Thread t : threads) { | |
t.join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment