tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "honyk" <>
Subject Directory watcher app
Date Mon, 14 Oct 2013 19:21:35 GMT
Hello Everyone,

in my web app I use Java 7 directory watcher feature.

When the final war file is placed into Webapps folder and Tomcat is started,
it freezes as it waits forever for any directory changes (the app is loaded
on tomcat startup).

I use the following workaround - calling my watcher code in a new Thread (in
the context init phase).

It does the job, but I am not sure if this is the best solution. Couldn't be
the same effect achieved using specific tomcat options?

What do you think?

Thanks, Jan

package my.util.jobticketprocessor;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ContextListener implements ServletContextListener {

    private static final Logger LOGGER =
    private Thread threadA;

    public void contextInitialized(ServletContextEvent event) {"Watcher - right before the init.");

        threadA = new Thread(new Runnable() {
            public void run() {
      "Thread - right before the init.");
      "Thread - right after the init.");
        }, "Thread A");

       "Watcher has been initialized successfully.");

    public void contextDestroyed(ServletContextEvent event) {
        try {
  "Thread has been terminated.");
        } catch (InterruptedException e) {
            LOGGER.error("Thread terminating has failed.");
        }"Watcher has been terminated.");

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message