public void dispose() { // Disable running flag running = false; // Worker thread try { // Join worker thread logger.debug(this + " waiting for worker thread to exit!"); join(60 * 1000); // If its still alive try to interrupt it if (isAlive()) { logger.debug(this + " interrupting worker thread."); interrupt(); } } catch (InterruptedException ie) { logger.info(this + " Interrupted waiting on worker thread exit!"); } // Snapshot thread try { // Stop snapshot thread if (metricWriter != null) { // Set stop flag metricWriter.interrupt(); // Wait to join logger.debug(this + " waiting metric snapshot writer thread to join"); metricWriter.join(60 * 1000); // If its still alive try to interrupt again if (metricWriter.isAlive()) { logger.debug(this + " interrupting snapshot thread."); metricWriter.interrupt(); } } } catch (InterruptedException ie) { logger.info(this + " Interrupted waiting on snapshot thread exit!"); } }