When creating Runnable’s (or other task related structures like Callable’s or your own Threads), make sure that you are logging exceptions. This week I was asked by a colleague to assist with a possible concurrency problem. The symptom was the disappearance of running tasks.
We added some extra debugging statements and added the name of the thread to the logging, but we still were not able to find the cause. After 15 minutes we figured out that the cause could be an exception that was not logged and therefore not visible in the logging. So we added a try/catch block around the content of the runnable, ran the application, and what do you guess? In the log stacktraces started to appear.
So when you are in charge of the top of the callstack (so running your own threads) make sure that you catch and log exceptions. If you don’t, it could lead to hard to find problems.