title: Split Files in a directory uniformly across threads in JAVA
body: <p>I have a variable list of files in a directory and I have different threads in Java to process them. The threads are variable depending upon the current processor</p>
  
  <pre><code>int numberOfThreads=Runtime.getRuntime().availableProcessors();
  
  File[] inputFilesArr=currentDirectory.listFiles();
  </code></pre>
  
  <p>How do I split the files uniformly across threads? If I do simple math like</p>
  
  <pre><code>int filesPerThread=inputFilesArr.length/numberOfThreads
  </code></pre>
  
  <p>then I might end up missing some files if the <code>inputFilesArr.length</code> and <code>numberOfThreads</code> are not exactly divisible by each other. What is an efficient way of doing this so that the partition and load across all the threads are uniform?</p>