I have a thread executor implementation where the cost of a wrapper is showing up as very costly. There is a wrapper class Task which is defined as follows:
 class Task {
   public Runnable r;       
   public Task(Runnable r) {          
     this.r = r;                                                                   
   }  
   public void run() {       
     r.run();      
   }     
 List<task> taskList;
For following case the run time is ~800ms.
  for (Task t : taskList) {                                                 
           t.r.run();                 
    }
While for the following case it is ~7000ms.
 for (Task t : taskList) {        
           t.run();                                                              
 }
It does not happen in isolation, but is happening inside the code of the executor. Just wondering if someone has a hint as to what might be going on?
The runnable being passed is the following for this test case:
class Tester implements Runnable {                                                 
  int i;                                                                           
  public Tester(int i) {                                                           
    this.i = i;                                                                    
  }                                                                                
  @Override                                                                        
  public void run() {                                                              
    //System.out.println(i);                                                       
    for (int j = 0; j < 1000000; j++) {                                            
      i = j;                                                                       
    }                                                                              
  }                                                                                
  public int getI() {                                                              
    return i;                                                                      
  }  
For reference, the code can be found on github.com/sharvanath/TempThreadPool. Run the ThreadPoolTest for getting the result of the execution. Now try changing line 41 of ThreadPool.java and see the magic.
 
     
    