Created
July 7, 2012 07:12
-
-
Save mike-neck/3065203 to your computer and use it in GitHub Desktop.
ExecutorServiceの拡張がうまくできん - こっちならできた … 名前空間の問題?
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
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] |
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 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