Let us assume we have a method:
public class DoStuff implements Runnable {
public void run()
{
A();
B();
C();
}
}
Is there a simple way to create n
threads that will run all A(), then all B(), then all C()?
I know that I can do something like:
ExecutorService app = Executors.newFixedThreadPool(threadCount);
//create A class and run A();
app.shutdown();
app.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
For A() then B() then C(), but I want something like the following:
public class DoStuff implements Runnable {
public void run()
{
A();
//wait all A to finish;
B();
//wait all B to finish;
C();
}
}
Using the same threads all the time.