I have a servlet automatically firing up when the app server starts, and in its init(), I'm making another thread:
init(){ new FooThread() }
in FooThread(), i want to periodically check the status of a DB value, then depending on the value, make a web service call. When these two tasks complete, I want the thread to sleep to wait a certain period then repeat.
This cycle would just continue forever.
FooThread:
public class FooThread implements Runnable{
Thread t;
FooThread(){
t = new Thread(this, "BBSThread");
logger.info("*** about to start " + t.getName());
t.start();
logger.info("*** started: " + t);
}
public void run() {
try{
while(true){
//do the db check, then conditionally do the web services call
logger.info("*** calling sleep() ***");
Thread.sleep(50000);
logger.info("*** now awake ***");
}
} catch (InterruptedException e) {
System.out.println("*** FooThread interrupted");
}
}
}