How to run X tasks on Y threads in Java?
<p>I want to meassure an average time of executing a task on 5 threads doing 100 tasks.</p>

<p>For time meassuring purposes I use <code>nanoTime()</code></p>

<p>The task is calling one specific method, let's call it <code>foo();</code>
I don't create any additional classes. </p>

<p>In my code I create a task:</p>

<pre><code>Runnable thExecute = new Runnable(){
  @Override
  public void run(){
    foo();
  }
};
</code></pre>

<p>And then I create a thread:</p>

<pre><code>Thread th = new Thread(thExecute);
long start = System.nanoTime();
th.run();
long stop = System.nanoTime();
</code></pre>

<p>This would be great if I had the same number of tasks as threads. 
I tried to create arrays of threads and tasks:</p>

<pre><code>Runnable[] thExecutes = new Runnable[100];
Thread[] ths = new Thread[5];
</code></pre>

<p>But now I don't know what to do next. I know they should be queued somehow and probably I should use <code>Executor</code> class. I use Java 6.</p>

<p>Edit: 
At first I didn't mean what I wrote. Now I know I want average time + highest time.</p>