Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Created July 7, 2012 07:12
Show Gist options
  • Save mike-neck/3065203 to your computer and use it in GitHub Desktop.
Save mike-neck/3065203 to your computer and use it in GitHub Desktop.
ExecutorServiceの拡張がうまくできん - こっちならできた … 名前空間の問題?
in Closure 1
in Closure 2
in Closure 3
in Closure 4
in Closure 5
in Closure 6
in Closure 7
in Closure 8
in Closure 9
in Closure 10
result -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
import java.util.concurrent.ExecutorService
import java.util.concurrent.Callable
import java.util.concurrent.Executors
ExecutorService.metaClass.define {
doCall = {Closure closure ->
return delegate.submit (new Callable(){
@Override
Object call() {
return closure ()
}
})
}
}
def executor = Executors.newSingleThreadExecutor()
def future = executor.doCall {
def list = []
(1..10).each {
println "in Closure ${it}"
list << it
}
return list
}
println "result -> ${future.get()}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment