Created
          July 7, 2012 06:40 
        
      - 
      
- 
        Save mike-neck/3065146 to your computer and use it in GitHub Desktop. 
    ExecutorServiceの拡張がうまくできん
  
        
  
    
      This file contains hidden or 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 Callable 1 | |
| in Callable 2 | |
| in Callable 3 | |
| in Callable 4 | |
| in Callable 5 | |
| in Callable 6 | |
| in Callable 7 | |
| in Callable 8 | |
| in Callable 9 | |
| in Callable 10 | |
| result get -> null | 
  
    
      This file contains hidden or 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 { | |
| submit = {Closure closure -> | |
| return delegate.submit (new Callable(){ | |
| @Override | |
| Object call() { | |
| return closure() | |
| } | |
| }) | |
| } | |
| } | |
| def executor = Executors.newSingleThreadExecutor() | |
| def future = executor.submit { | |
| def list = [] | |
| (1..10).each { | |
| println "in Callable ${it}" | |
| list << it | |
| } | |
| return list | |
| } | |
| println "result get -> ${future.get()}" | 
インタフェースのメソッドなので、実装は継承したクラスで上書きされるみたいですね。
さらに上から塗り替えるメソッドを定義すれば動くようです。
( https://gist.github.com/3065503 )
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
submitはExecutorServiceインタフェースのメソッドのようですので、名前がかぶっているため使えなかったんだと思われます。https://gist.github.com/3065304
と、思ったら既に同じ結論に辿り着かれておられた( https://gist.github.com/3065203 )ようですね、これは失礼^^;