Created
November 2, 2014 16:54
-
-
Save vaclav/75da6dde2050ffc09dbf to your computer and use it in GitHub Desktop.
GPars - producer / up-to-ten consumers
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.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