import java.util.concurrent.Callable
import java.util.concurrent.Executors
def executorService = Executors.newFixedThreadPool(4)
def x = {
20.times {
println "X"
}
} as Callable
def y = {
20.times {
println " Y"
}
} as Callable
executorService.invokeAll([x, y])
executorService.shutdown()
which of course has an output similar to this:
X
Y
Y
Y
X
Y
X
Y
X
Y
Y
X
X
Y
X
Y
Y
X
X
X
Pretty neat, huh?
No comments:
Post a Comment