title: Java, Passing value to a constructor of class inplementing Callable
body: <p>So, I have implemented the following simple class to parallelize the independent encryption processes:</p>
  
  <pre><code>public class SelectionEncryptor implements Callable&lt;BigInteger&gt; {
  
      private DamgardJurik dj;
      private byte c;
      private int s;
  
      public SelectionEncryptor(DamgardJurik dj, byte c, int s) {
          this.dj = dj;
          this.c = c;
          this.s = s;
      }
  
      @Override
      public BigInteger call() throws Exception {
  
          dj.setS(s);
  
          BigInteger r = dj.encryption(BigInteger.valueOf(c));
          System.out.println("dj s: " + dj.s + ", given s: " + s + ", c: " + c); 
  
          return r;
      }
  
  }
  </code></pre>
  
  <p><strong>s</strong> is just a parameter of the cryptosystem we use, but it is an important one determining the depth of the encryption.</p>
  
  <p>I initialize and run my threads as following:</p>
  
  <pre><code>int s = s_max;
  
  ExecutorService executor = Executors.newFixedThreadPool(selectionBits.length);
  ArrayList&lt;Future&lt;BigInteger&gt;&gt; list = new ArrayList&lt;Future&lt;BigInteger&gt;&gt;();
  
  // selectionBits is just a byte array holding 1's and 0's
  for (int i = 0; i &lt; selectionBits.length; i++) {
  
      dj.setS(s);
  
      SelectionEncryptor se = new SelectionEncryptor(dj, selectionBits[i], s);
      System.out.println("submitted: " + selectionBits[i] + " with s " + s + ", dj s: " + dj.s);
  
      Future&lt;BigInteger&gt; result = executor.submit(se);
      list.add(result);
  
      s--;
  }
  
  // collecting results
  
  for (Future&lt;BigInteger&gt; future : list) {
      try {
          BigInteger f = future.get();
          out.println(f);
      } catch (InterruptedException | ExecutionException e) {
          e.printStackTrace();
      }
  }
  
  executor.shutdown();
  </code></pre>
  
  <p>The problem is, even if I send the correct <strong>s</strong> values to the SelectionEncryptor, it just uses different values for it. This is an example output of my program:</p>
  
  <pre><code>submitted: 1 with s 6, dj s: 6
  submitted: 0 with s 5, dj s: 6
  submitted: 1 with s 4, dj s: 5
  submitted: 0 with s 3, dj s: 3
  submitted: 1 with s 2, dj s: 2
  submitted: 0 with s 1, dj s: 1
  dj s: 4, given s: 1, c: 0
  dj s: 2, given s: 2, c: 1
  dj s: 2, given s: 3, c: 0
  dj s: 2, given s: 4, c: 1
  dj s: 2, given s: 6, c: 1
  dj s: 2, given s: 5, c: 0
  </code></pre>
  
  <p>I have tried setting <strong>s</strong> only in my main function, only in the callable class and now I'm setting it in both of them just to be safe but none of them have worked yet.</p>
  
  <p>What can be the source of this problem? Do those callable instances share the DamgardJurick object? What I'm missing?</p>
  
  <p>Sorry about the long question, I couldn't find a way to make it simpler.</p>