This question is the culmination of a few questions leading up to it. I just want to make sure I have everything right before I commit any changes that I've made.
So here's what I'm working with for data structure:
In an abstract class:
public abstract void doRun();
public void run(){
try{
while(!Thread.currentThread().isInterrupted() || hasRunBefore){
doRun();
}
}catch (InterruptedException e){Thread.sleep(1); System.out.println("Thread Interrupted: "); e.printStackTrace(); }
}
Then in the child classes that are implementing my abstract class:
public void doRun(){
doChildClassStuff();
}
Then when calling these in my main class I simply do
ClassName myClass = new ClassName(constructor.list);
ExecutorService threadPool = Executors.newFixedThreadPool(12);
List<Future<?>> taskList = new ArrayList<Future<?>>();
taskList.add(myClass);
for(Future future : taskList){
try{
future.get(1, TimeUnit.SECONDS);
}catch(CancellationException cx){ System.err.println("Cancellation Exception: "); cx.printStackTrace();
}catch(ExecutionException ex){ System.err.println("Execution Exception: ");ex.printStackTrace();
}catch(InterruptedException ix){ System.err.println("Interrupted Exception: ");ix.printStackTrace();
}catch(TimeoutException ex) {future.cancel(true);}
}
threadPool.shutdown();
threadPool.awaitTermination(60, TimeUnit.SECONDS);
threadPool.shutdownNow();
and if thread.sleep() fails, that means that the thread has been interrupted and should exit. If all the threads take over 60 seconds then they will all be sent thread.interrupt() commands from the awaitTermination, right?
Am I completely off-base here?