Created
December 7, 2014 08:33
-
-
Save wololock/7f1348e04f68710e42d2 to your computer and use it in GitHub Desktop.
GPars parallel actors example
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
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