A servlet is just a Java class. You can do anything you can do with the java language, including start threads. The following starts a thread that runs some task every 10 minutes. The thread is started in the servlet init method. I choose to set the thread to daemon mode, meaning that when the main thread of execution shuts down the mailer thread will automatically be killed. Otherwise you need to be sure to keep track of it and be sure to signal it to shutdown in your Servlet.destroy method.

public class MyServlet extends HttpServlet
{
   private static class MailerThread extends Thread
   {
      public void run ()
      {
         while (true)
         {
             // do something
            synchronized (this)
            {
               wait (10*60*1000);
            }
         }
      }
   }

   // the servlet init method
   public void init ()
   {
      MailerThread thread = new MailerThread ();
      thread.setDaemon (true);
      thread.start ();
   }

   // ... doGet, etc. ...
}

-Erik

Eric C wrote:

Use cron under unix and/or a java app that would use Javamail classes.
Of course you can do it inside a servlet.

----- Original Message -----
From: "Prince" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Saturday, November 01, 2003 8:51 AM
Subject: HOW CAN I USE THREADS IN TOMCAT




Hi,
I need to send a mail automatically at 10 minutes interval. how can i do
this? how can i activate threads in tomcat?
regards
Prince

----- Original Message -----
From: "Bill Barker" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, November 01, 2003 1:00 PM
Subject: Re: Opinions




The recent port of the 3.3 variable-substitution to Tomcat 5 may very


well


solve your problems here :).  The ports are supposed to move to
commons-digester, so should be available in 4.1.30 as well.

"Francois JEANMOUGIN" <[EMAIL PROTECTED]> wrote in
message



news:[EMAIL PROTECTED]




Hu! It's in early developments or is it suitable for production ?


It's ready for production. People are already using it in production
with tomcat 5. Of course, I'm biased ;)


Well, there is that beta flag in front of tomcat5 that tell me that your
opinion is more than biased :). Of course, I saw a mail telling that the
beta flag is related to specification instability (not code), anyway...



It's a Developer, rather than Sysadmin, option. Chances are you won't
need to worry about it as you'll use commons-daemon with tomcat, which
already does the required jsvc invocation for you.


Well, that does not help that much. I hope that there will be a
configuration scheme that'll let easily define user/group/port and so on


for


the connectors. Just waiting for a sysadmin point of view :).

Thanks,

François.




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







--
http://www.spectacle.ca/
The New Online Source for Live Music in Montreal
.::514.286.1699::.



Reply via email to