Tweaking multithread code for error handling.

Supports database connection errors. Restarts threads that error during
execution.