I used this code to start a listener before Tomcat initializes, but it has a while loop in it that will check a database every 5 seconds for changes. Is there any way that I can skip the looping part of that until my web service has been started completely, then trigger the loop to begin checking?
EDIT: Meant listener
and not Servlet
EDIT2: Code below
public class DatabaseChecker implements ServletContextListener {
final static String URL = "redacted";
final static String USER = "redacted";
final static String PASS = "redacted";
@Override
public void contextInitialized(ServletContextEvent event) {
Vector<String> completedJobs = new Vector<String>();
try {
while(true) { // loop to always check & notify
Thread.sleep(5000);
System.out.println("Checker running ...");
// completedJobs = selectCompletedJobs();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("ServletContextListener destroyed");
}
}