Created
October 21, 2017 07:44
-
-
Save gevorg/90258b6f3566163d87834c5c1aa788b8 to your computer and use it in GitHub Desktop.
GPars demo
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
// compile "org.codehaus.gpars:gpars:1.2.1" | |
import groovyx.gpars.GParsPool | |
... | |
static void main(String[] args) { | |
def aPromises = [] | |
for (int i = 0; i < 10; ++i) { | |
aPromises << { | |
println "START: ${Thread.currentThread().id}" | |
Thread.sleep(5000) | |
println "DONE: ${Thread.currentThread().id}" | |
} | |
} | |
GParsPool.withPool(5) { | |
println "BEFORE" | |
GParsPool.executeAsyncAndWait aPromises | |
println "AFTER" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment