title: Java- reusing a thread with the same run but different parameters
body: <p>I still have some trouble wrapping my head around threads, and I'm trying to do this in the simplest way possible. I know that threads all have to have a run method they inherited from the Runnable class, but they can have additional methods as well, correct?</p>
  
  <p>The reason being, I have a thread with some private variables and a run method. It calls it's run function, and once it's done, I want to reuse the thread with the exact same run method. It does exactly the same thing, just with different variables. So can I add something like a setArray method (the thread contains a private byte array) so I can just simply call run again with this new array, or is that not allowed. I guess to put it simply, it'd be something like</p>
  
  <pre><code>Thread thread = new MyThread();
  thread.start();
  
  // Check if the thread has finished in a non-blocking way
  if (thread.isAlive() == false) {
      thread.setArray(newArray)
      thread.start();
  }
  </code></pre>
  
  <p>Basically I only have a fixed number of threads and when the first thread is done running, I want to change the parameters a bit and have it run again. I don't wan them to die, which seems to be what join does.</p>
  
  <p>For the specific problem, I have say 4 threads, that each are give a set size block of a larger byte array. Each thread compresses that array with a Deflater and passes their result to a manager object that handles the synchronization. Once the first thread (as in the thread that got the first part of the array, not the first to finish) is done, it moves on to the next block not assigned to a thread.</p>
  
  <p>I know thread pools are an option, but it seems a bit overkill plus I really don't understand them (I'm still having trouble with just normal threads).</p>