I'm developing a web application using Spring Framework 4.2 with Apache Tomcat 8.5. When I modify a file in a directory, I need to call a method in a bean object in order to reload the information. I work with Apache Commons IO to watch the directory, however when I undeploy the application, the thread which scan the directory still lives.
This is the code to watch the changes
final File directory = new File(groupsDirectory);
FileAlterationObserver fao = new FileAlterationObserver(directory);
fao.addListener(new FileAlterationListenerImpl());
final FileAlterationMonitor monitor = new FileAlterationMonitor(pollingInterval);
monitor.addObserver(fao);
monitor.start();
And this the message that Tomcat shows me when I undeploy the webapplication:
22-May-2016 19:13:14.377 WARNING [http-nio-8084-exec-12] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [Argo] appears to have started a thread named [Thread-12] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Thread.sleep(Native Method) org.apache.commons.io.monitor.FileAlterationMonitor.run(FileAlterationMonitor.java:188) java.lang.Thread.run(Thread.java:745)