Skip to content

Instantly share code, notes, and snippets.

@vaclav
Created November 2, 2014 16:54
Show Gist options
  • Save vaclav/75da6dde2050ffc09dbf to your computer and use it in GitHub Desktop.
Save vaclav/75da6dde2050ffc09dbf to your computer and use it in GitHub Desktop.
GPars - producer / up-to-ten consumers
import groovyx.gpars.dataflow.DataflowQueue
import static groovyx.gpars.dataflow.Dataflow.task
import static groovyx.gpars.dataflow.Dataflow.operator
/**
* A simple producer consumer sample showing use of the DataflowQueue class.
*/
def words = ['Groovy', 'fantastic', 'concurrency', 'fun', 'enjoy', 'safe', 'GPars', 'data', 'flow']
final def buffer = new DataflowQueue()
task {
for (word in words) {
buffer << word.toUpperCase()
}
}
operator(inputs:[buffer], outputs:[], maxForks: 10) {value->
println ('' + value + Thread.currentThread())
}
sleep 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment