Created
July 7, 2012 08:35
-
-
Save aya-eiya/3065503 to your computer and use it in GitHub Desktop.
Alterメソッドでsubmit処理を変更してみる
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.BlockingQueue | |
import java.util.concurrent.LinkedBlockingQueue | |
import java.util.concurrent.Executors | |
import java.util.concurrent.Callable | |
ExecutorService.metaClass.define { | |
alter = { | |
this.submit = {Closure closure -> | |
return delegate.submit (new Callable(){ | |
@Override | |
Object call() { | |
return closure() | |
} | |
}) | |
} | |
this | |
} | |
} | |
def executor = Executors.newSingleThreadExecutor().alter() | |
def future = executor.submit { | |
def list = [] | |
(1..10).each { | |
println "in Callable ${it}" | |
list << it | |
} | |
return list | |
} | |
println "result get -> ${future.get()}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment