-1

I have requirement saying that i want execute the mailing code without any event but based on timer when the specified time comes that code as to execute and the mail has to send .

package com.uttara.reg;
import java.util.TimerTask;
public class Timer extends TimerTask {
    @Override
    public void run() {
        // TODO Auto-generated method stub

    }

}

i can't understand how to call timer class

Could anybody plz help me out!!! Thanks in advance

user2838630
  • 91
  • 1
  • 5
  • 15

3 Answers3

2

you can try a few things

1 : Timer class

2 : TimerTask class

3 : Quartz

4 : Cron

5 : Scheduler

or if you have a very simple requirement then

step 1 : create a thread to get time

step 2 : in the thread keep

if(time_by_thread == time_want_to_execute)
{
//execute your timer code here
}
0

check out Timer and Scheduler classes.

Alex Suo
  • 2,977
  • 1
  • 14
  • 22
0

You can user Timer as follows:

    Timer timer = new Timer(); 
    timer.schedule(new TimerTask() {
       @Override
       public void run() {
       // Your code
       }
    }, your delay);

Or

// creating timer task, timer
      TimerTask tasknew = new TimerScheduleDelay();
      Timer timer = new Timer();

      // scheduling the task at interval
      timer.schedule(tasknew, 100);      
   }

   // this method performs the task
   public void run() {
      System.out.println("timer working");      
   }

This should be separated from a Java EE app server. You can use Quartz, or an operating system scheduled task, or a batch manager i.e. AutoSys, but implementing it into a servlet is not preferable and usefull to me. Java EE have a TimerService you can use that.

milind_db
  • 1,274
  • 5
  • 34
  • 56