Skip to content

Instantly share code, notes, and snippets.

@aya-eiya
Created July 7, 2012 08:35
Show Gist options
  • Save aya-eiya/3065503 to your computer and use it in GitHub Desktop.
Save aya-eiya/3065503 to your computer and use it in GitHub Desktop.
Alterメソッドでsubmit処理を変更してみる
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