(快速参考)

Agent 实现类似 Clojure 的 Agent 概念

import groovyx.gpars.agent.Agent

def jugMembers = new Agent<List>(['Me']) //add Me

jugMembers.send {it.add 'James'} //add James

final Thread t1 = Thread.start { jugMembers {it.add 'Joe'} //add Joe (using the implicit call() method to send the function) }

final Thread t2 = Thread.start { jugMembers << {it.add 'Dave'} //add Dave jugMembers << {it.add 'Alice'} //add Alice }

[t1, t2]*.join() println jugMembers.val jugMembers.valAsync {println "Current members: $it"}

System.in.read() jugMembers.stop()