Servlet an Threads

Hello,

When my web application starts I would like to start a thread which checks some records in the database every 24 hours and sends an e-mail to the administrator.

Does anyone know how to do this ?

I suggest I make a servlet which I initialize on startup of my application.

(in the web.xml)

In the Init() method of this servlet I instantiate a Thread which executes every 24 hours.

Is this correct ?

Regards,

Tommie Denoble.

[483 byte] By [Tommie.Denoblea] at [2007-11-26 19:55:23]
# 1
Hello,This is a solution with the tag "<load-on-startup>" set to 1 for example.This will ensure the servlet will be loaded at startup.You can also register listener on many events like session,context ....Regards,Sebastien Degardin.
sdegardina at 2007-7-9 22:48:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi Tommie,

You're correct. It is one of the ways to achieve what you want.

The other way is to write your own class that implements the javax.servlet.ServletContextListener interface: http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html

In particular, you will want to implement the "contextInitialized()" method.

Then in your web.xml, simply add in a <listener> tag to reference your class.

singchyuna at 2007-7-9 22:48:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...