In the previous Java Multithreading in Practice we discussed simplifying the base Java API for increased readability and reliability. However, after further analysis catching exceptions was still not full-proof. The end-user (of the API) would still need to remember to catch
Exception in their
Callable<Void>s. A working solution is to automatically do that internally in the custom
ThreadPool class (not Java's
ThreadPool class) with two protected methods,
toSafeCallable(Callable<Void>). All these do is wrap the passed in argument in try catch block, catch
Exception and log it as an error. This lets the end user not have to worry about exceptions being lost in the system.
In-line code is now monospaced and green to let it stand out. I hope that this helps people read the blog!