Skip to content

Instantly share code, notes, and snippets.

@gevorg
Created October 21, 2017 07:44
Show Gist options
  • Save gevorg/90258b6f3566163d87834c5c1aa788b8 to your computer and use it in GitHub Desktop.
Save gevorg/90258b6f3566163d87834c5c1aa788b8 to your computer and use it in GitHub Desktop.
GPars demo
// 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