Skip to content

Instantly share code, notes, and snippets.

@wololock
Created December 7, 2014 08:33
Show Gist options
  • Save wololock/7f1348e04f68710e42d2 to your computer and use it in GitHub Desktop.
Save wololock/7f1348e04f68710e42d2 to your computer and use it in GitHub Desktop.
GPars parallel actors example
import groovyx.gpars.group.DefaultPGroup
import groovyx.gpars.scheduler.DefaultPool
def poolGroup = new DefaultPGroup(new DefaultPool(true, 5))
def closure = {
when {Integer msg ->
println("I'm number ${msg} on thread ${Thread.currentThread().name}")
Thread.sleep(1000)
stop()
}
}
def integers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
def actors = integers.collect { poolGroup.messageHandler(closure) << it }
actors*.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment