Created
September 21, 2022 14:50
-
-
Save daniellansun/e077a5f5bf395051718df881c0922812 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
import java.time.* | |
import java.util.concurrent.* | |
import java.util.concurrent.atomic.* | |
def atomicInteger = new AtomicInteger() | |
def runnable = () -> { | |
atomicInteger.incrementAndGet() | |
} | |
def start = Instant.now() | |
try (def executor = Executors.newVirtualThreadPerTaskExecutor()) { | |
for(int i = 0; i < 1_000_000; i++) { | |
executor.submit(runnable) | |
} | |
} | |
def finish = Instant.now() | |
def timeElapsed = Duration.between(start, finish).toMillis() | |
println "Result: ${atomicInteger}. Total elapsed time: ${timeElapsed}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment