class BgThread extends Thread { // Create a logger. For more information on the logging api's, // see The Quintessential Logging Program Logger logger = Logger.getLogger("com.mycompany.mypackage"); BgThread() { // As a daemon thread, this thread won't prevent the application from exiting setDaemon(true); } // Set to true to shut down this thread boolean stop = false; public void run() { while (!stop) { try { // Perform work here } catch (Throwable t) { // Log the exception and continue logger.log(Level.SEVERE, "Unexception exception", t); } } } }