So far in my experiments with the executorservice I've had a lot of advice that involves using future.get, and then future.cancel in order to throw a thread interrupt which then needs to be caught in the thread, and handled there. My question is a little different.
Assuming that I was running a thread that simply kept track of how long things were running and if they passed by some threshold, would this be a good way to kill the executorservice and all running threads?
Example thought process:
ExecutorService threadPool = Executors.newFixedThreadPool(12);
timekeeper.start();
List<Future<?>> taskList = new ArrayList<Future<?>>();
for (int i = 0; i < objectArray.length; i++) {
Future<?> task = threadPool.submit(new ThreadHandler(objectArray[i], i));
taskList.add(task);
Thread.sleep(500);
}
if(timekeeper.now() > 60)
threadpool.shutdownNow();
}
Would this work? I have no way to check since my threads fail extremely infrequently (about 1/700 runs, and only at certain hours of the day when I'm not working).