0

If an uncaught exception is thrown and you want to recover by restarting an identical thread to the one the exception was just thrown in (e.g JMS connection lost), what's the easiest way?

The class extends from Thread, and the thread has an UncaughtExceptionHandler.

kkudi
  • 1,625
  • 4
  • 25
  • 47
  • 2
    Can you show some code? And I assume you are not able to catch `Exception` in your run method to handle this appropriately? – Gray Apr 15 '13 at 14:17

1 Answers1

1

The easiest thing to do is to "restart" the current thread via the run() method

void run() {
    boolean done = false;
    while(!done) {
        try {
           ...
           done = true;
        } catch (ConnectionLostException ex) { 
            // log exception
        }
    }
}
Zim-Zam O'Pootertoot
  • 17,888
  • 4
  • 41
  • 69