RE: Timer implementation with servlet

2004-04-20 Thread Aaron Smuts
For one, it looks like you are using the wrong schedule method if you
want it to repeat.  Also, the delay is in millis.  So, you have it set
for 1 second.

If you want it to repeat, you have to use the 3 arg method.  

timer.schedule(new SessionTrack(), 0, 6);

http://java.sun.com/j2se/1.3/docs/api/java/util/Timer.html#schedule(java
.util.TimerTask,%20long)


Aaron Smuts

> -Original Message-
> From: Jignesh Patel [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, April 20, 2004 10:01 AM
> To: [EMAIL PROTECTED]
> Subject: Timer implementation with servlet
> 
> Hi All,
> I am trying to implement timer with servlet but it works only at the
time
> of
> loading only while I schedule it to work after every 1 minute.
> What is the reason for not working later on?
> 
> My servlet code is as follows:
> public class TimerServlet extends GenericServlet implements
> SingleThreadModel
> {
>   public void init(ServletConfig config) throws ServletException {
>   Timer timer = new Timer();
>   System.out.println("timer started");
>   timer.schedule(new SessionTrack(),1000);
>   }
>   public void service(ServletRequest arg0, ServletResponse arg1)
> throws
> ServletException, IOException {
> 
>   }
>   public String getServletInfo() {
>return null;
>   }
> 
> }
> And code for TimerTask is as follows:
> 
> public class SessionTrack extends TimerTask {
>  public void run(){
>   System.out.println("sending email");
>   Mailer mailer = new Mailer();
>   mailer.sendMail("profile","[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]



Timer implementation with servlet

2004-04-20 Thread Jignesh Patel
Hi All,
I am trying to implement timer with servlet but it works only at the time of 
loading only while I schedule it to work after every 1 minute. 
What is the reason for not working later on?

My servlet code is as follows:
public class TimerServlet extends GenericServlet implements SingleThreadModel 
{
public void init(ServletConfig config) throws ServletException {
Timer timer = new Timer();
System.out.println("timer started");
timer.schedule(new SessionTrack(),1000); 
}
public void service(ServletRequest arg0, ServletResponse arg1) throws 
ServletException, IOException {

}
public String getServletInfo() {
 return null;
}

}
And code for TimerTask is as follows:

public class SessionTrack extends TimerTask {
 public void run(){
System.out.println("sending email");
Mailer mailer = new Mailer();
mailer.sendMail("profile","[EMAIL PROTECTED]");
 }
}



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