title: inconsistency in java thread
body: <p>I have written a class to check the status of batch API. below is the implementation.</p>
  <pre><code>//Inner class
  private class CallBatchStatus implements Runnable {
      private String batchId;
        
      public CallBatchStatus(String batchId) {
            this.batchId = batchId;
      }
  
      @Override
      public void run() {
         getBatchStatus(this.batchId);
      }
  
   }
  </code></pre>
  <p>Similarly, there is one more inner class</p>
  <pre><code>//Inner class
  private class GetBatchStatus {
      private String batchId;
      public GetBatchStatus(String batchID, ExecutorServcie exc){
          this.batchId = batchID;
          exc.execute(new CallBatchStatus(this.batchId));
     }
  }
  </code></pre>
  <p>and private method in outer class</p>
  <pre><code>//Recursive Private method call of outer class
  private getBatchStatus(String batchId) {
      String response = httpCall(batchId);
      if(!response.equals(&quot;COMPLETE&quot;)) {
          resposne = getBatchStatus(batchId);
       }
       return response;
  }
  </code></pre>
  <p>I am executing these threads with the help of executor framework by passing <code>batchIds</code> like below:</p>
  <pre><code>ExecutorService executorService = Executors.newFixedThreadPool(5);
  List&lt;GetBatchStatus&gt; listOfBatch = batchIds.stream().map(batchId -&gt; new GetBatchStatus(batchId, executorService )).collect(Collector.toList());
  </code></pre>
  <p>Let say I am passing two batch ids and it is executing properly but sometimes I am getting the COMPLETE status of the batch which is processing and STARTED status of the batch which already has been executed. I do not understand how the response variable in getBatchStatus is overriding/ exchanging as this is a local variable and running in a different thread.</p>