I am trying to run multiple threads concurrently, where each thread is computing value for a particular point in time and returning a result. I was thinking of using the Executor class but it seems am not doing it correctly. I was wondering if this piece of code is correct for that. Or what is the best way of doing this?
ExecutorService tasker = Executors.newFixedThreadPool(20);
for(double t = 0.0; t<=5.0; t = t + 0.50 ){ // t is time interval
tasker.execute(new MyThread(t));
}
You dont need to pass a Thread inside the execute method.
Instead you need to pass a Runnable object, like so: