Created
November 1, 2014 20:34
-
-
Save vaclav/8bd831f81ba9c38106b8 to your computer and use it in GitHub Desktop.
GPars - producer-2 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 | |
/** | |
* 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() | |
} | |
} | |
task { | |
while (true) println buffer.val | |
} | |
task { | |
while (true) println buffer.val | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment