Back Home

Groovy Json

2.3 Features

Threading

def myClosure = {num -> println "I Love Groovy ${num}"}
def threadPool = Executors.newFixedThreadPool(4)
 try {
  List<Future> futures = (1..10).collect{num->
    threadPool.submit({->
    myClosure num } as Callable);
  }
  // recommended to use following statement to ensure the execution of all tasks.
  futures.each{it.get()}
}finally {
  threadPool.shutdown()
}

- See more at: http://www.tothenew.com/blog/how-to-use-thread-pooling-using-groovy/#sthash.joLlrNay.dpuf

Misc

 
groovy.txt · Last modified: 2016/09/28 03:41 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd