title: Java Future. It suceeds in debug mode but fails when i run it normally
body: <p>Guys I'm facing a similar situation
  like 
  <a href="https://stackoverflow.com/questions/15169104/unit-test-succeeds-in-debug-mode-but-fails-when-running-it-normally">This junit case on another thread</a>
  though i don't have a junit  case. I  tried everything that i know of.. including suggestion on that link page, keeping a countdown and thread sleep but the results don't change. if i run through debug and give it some time it shows me all the results from all the thread but if i run it normally it invariably gives me less results.
  My code is as belows   </p>
  
  <p>`</p>
  
  <pre><code>    AtomicInteger atomicInteger = new AtomicInteger(employeeids.size());
      CountDownLatch latch = new CountDownLatch(employeeids.size());
      Iterable&lt;List&lt;String&gt;&gt; batchList = createBatches(employeeids, batchSize);
  
       Set&lt;Future&lt;List&lt;GradeSearchDTO&gt;&gt;&gt; set = new HashSet&lt;Future&lt;List&lt;GradeSearchDTO&gt;&gt;&gt;();
  
  
      for(List&lt;String&gt; employeeidsList: batchList) {
  
          Callable&lt;List&lt;GradeSearchDTO&gt;&gt; callable = new ScheduleCallable( employeetype, employeedetails,  employeeidsList,  dept, seeker, atomicInteger,latch );
          Future&lt;List&lt;GradeSearchDTO&gt;&gt; future = pool.submit(callable);
          set.add(future);
        try {
          Thread.sleep(1000);
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      }
  
  
      try {
          latch.await(getTimeOutInMillis(), TimeUnit.MILLISECONDS);
      } catch (InterruptedException e1) {
          // TODO Auto-generated catch block
          throw new EmployeeException("Building of Schedules didn't finish in time of ["+getTimeOutInMillis()+"] millis. ");
  
      }
  
      long timeLeft = getTimeOutInMillis();
      boolean check=true;
      while (check){
          logger.debug("Waiting for building asset. countdown value is[" + timeLeft+"]");
          try {
              Thread.sleep(TIME_TO_PAUSE);
              timeLeft = timeLeft - TIME_TO_PAUSE;
              if(timeLeft == 0 || timeLeft &lt; 0){
                  throw new EmployeeException("Building of Schedules didn't finish in time of ["+getTimeOutInMillis()+"] millis. ");
              }
              for (Future&lt;List&lt;GradeSearchDTO&gt;&gt; future : set) {
                  if(!future.isDone()){
                      check=true;
                      break;
                  }
                  else{check=false;}
                }
  
          } catch (InterruptedException e) {
              logger.error("Error waiting for asset to build to bulid");
          }
      }
  
      for (Future&lt;List&lt;GradeSearchDTO&gt;&gt; future : set) {
          try {
              EmployeeScheduleList.addAll(future.get());
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (ExecutionException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
        }
  
  
  
   public static class ScheduleCallable implements Callable 
  
  { 
      private String employeetype;
      private List&lt;Employee&gt;  employeedetails;
      private List&lt;String&gt; employeeidsList;
      private String dept;
      private EmployeeSeekerHelper seeker;
      private AtomicInteger atomicInteger;
      private CountDownLatch latch;
  
       public ScheduleCallable(String employeetype,List&lt;Employee&gt; employeedetails, 
       list&lt;String&gt; employeeidsList, String dept,EmployeeSeekerHelper seeker,AtomicInteger
      atomicInteger,CountDownLatch latch )
  
      {
  
      this.employeetype = employeetype;
      this.employeedetails = employeedetails;
      this.employeeidsList = employeeidsList;
      this.dept = dept;
      this.seeker = seeker;
      this.atomicInteger=atomicInteger;
      this.latch=latch;
      }
  
      public List&lt;GradeSearchDTO&gt; call() 
      {
      List&lt;GradeSearchDTO&gt; EmployeeScheduleList =  new ArrayList&lt;GradeSearchDTO&gt;(0) ;
  
      int counter=1;
  
      for(String scheduleId : employeeidsList)
  
      {
  
       latch.countDown();
  
      EmployeeScheduleList.addAll(searchEmployeeRulesForSchedule(employeetype,employeedetails,scheduleId,dept,seeker,latch));
      System.out.println("Thread COUNTER "+counter);
      atomicInteger.decrementAndGet();
      counter++;
      // latch.countDown();
  
      }
  return EmployeeScheduleList;
  
      }
  }
  </code></pre>
  
  <p>`</p>