In my program I have a class called "Vehicle" which extends from Thread, the thing is that at a certain point I need these Threads to create a Task (Runnable) and I want all these tasks to be managed by the same Threadpool, the problem is that if I call a method from a different class that contains this Pool, every other thread is creating a different pool. How can I avoid this? Thanks in advance.
public class Station {
Arrivals arrivals;
Vehicle k;
ListPumps lp;
ExecutorService executor = Executors.newFixedThreadPool(3);
public synchronized void startWork(Pump p) {
Runnable w = new Work(p);
executor.execute(w);
executor.shutdown();
while (!executor.isTerminated()) {
}
System.out.println("Finished all threads");
}
}