9
如何正确停止Java中的线程?
我需要一个解决方案来正确停止Java中的线程。 我有IndexProcessor实现Runnable接口的类: public class IndexProcessor implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(IndexProcessor.class); @Override public void run() { boolean run = true; while (run) { try { LOGGER.debug("Sleeping..."); Thread.sleep((long) 15000); LOGGER.debug("Processing"); } catch (InterruptedException e) { LOGGER.error("Exception", e); run = false; } } } } 我有ServletContextListener启动和停止线程的类: public class …