> Can anyone answer my question?
> How can I automatically start a servlet in a specific time? For
> example: at
> midnight.
> I don't want to start it when I start my webserver.

Create an intialisation servlet who's init() method is called when the web
application comes into scope. In the init() method spawn a new thread and
sleep until the apropriate time and then call whatever method you need to
execute at that time. You should be able to set up multiple actions on one
sleeping thread if required. Use a timer object or some other helper to
manage your sleeping.

Be sure also to have a destroy method that shuts down the sleeping thread,
otherwise you thread will keep running when you remove your web application
and the only way to get rid of it will be to restart the whole server.

this code runs periodically, you'll have to do something slightly different
to do something at a particular time of day

   /**
    * Called by the container when the application comes into scope (ie on
application load)
    *
    * Starts the memory logger
    */
   public void init() {
      if (timer != null) {
         WebLogger.log("timer not null aborting MemoryDaemon start");
         return;
      }
      timer = new Timer(true);
      timer.schedule(new DaemonTask(), 0, DELAY_MINS * SECS_MIN *
MILLIS_MIN);
      WebLogger.log("initialised MemoryDaemon");
   }


   /**
    * Called by the container when the servlet goes out of scope (ie on
application reload)
    */
   public void destroy() {
      WebLogger.log("Shutting down MemoryDaemon");
      timer.cancel();
   }


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to