So right now I have a fairly basic Executor service that I use to break my program into threads, like so:
ExecutorService threadPool = Executors.newFixedThreadPool(12);
for (int i = 0; i < objectArray.length; i++) {
threadPool.submit(new ThreadHandler(objectArray[i], i));
// The i is used elsewhere
}
I was wondering if there was a good way to detect / close “crashed” or “frozen” threads? I took a look at the documentation but it doesn’t really seem to fit in with how I’m using this at all…
Can someone help me with this? Thanks
threadPool.submitreturnsFuture<T>Object. So using this future Object you can have handle on your task execution.By using
isCancelled() and isDonemethod you can check task has been canceled or done. Even moreget()is blocking call which throws exception on interpret or cancel or in executionexception.