You should create a servlet that creates a new thread in it's init() method
:
******* IN WEB.XML :
<servlet>
<servlet-name>config</servlet-name>
<servlet-class>your.servlet.class.name</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
By adding the line <load-on-startup>1</load-on-startup>, you're telling the
servlet context to call the init() method of your servlet when it loads.
This is the ideal place to start a new working thread.
******** In your servlet code, override the init() method:
public void init(ServletConfig config) throws ServletException
{
//Start the new thread:
MySNMPThread thread = new MySNMPThread();
thread.start();
}
**** CREATE THE THREAD CLASS
public class MySNMPThread extends Thread
{
public void run()
{
try
{
//Start an infinite loop :
while( true )
{
//Do what you need to do here !
sleep(10000); //Sleep for the specified time (in
milliseconds)
}
} catch( InterruptedException e )
{
//The thread has been interrupted... we are closing
}
}
}
HTH,
David
-----Message d'origine-----
De : A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED] la part de Omer Tariq
Envoy� : 2 mars, 2003 04:20
� : [EMAIL PROTECTED]
Objet : Application level Servlets
Hi again,
In my web application, I need a trigger that will be executed the system
time is greater than one of the (date/time) fields in the database. The
trigger then needs to call a method in another class (an SNMP API that would
allow me to disable a switch's port). I'd like to ask where I should put the
trigger code: Could I code a servlet that could run during the lifetime of
an application?
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com