I have got the requirement to set the timer from user input.What basically is my requirement is..
1.Design a jsp page with input fields to set the date and time of timer ..
2.Take these input field values and set the date and time.
3.Execute the timer on the newly set date and time..
Actually i need to trigger mail at particular date and time and these date and time will be dynamically changed from user side to interacting to the jsp page.If date and time has been changed then it should trigger timer on that particular date and time leaving last one..
Currently i have a java class with main method which contains timer with hard-coded date and time which i need to change and give this facility to user to set and time ..
Please guys help me how to get from jsp page and Use it in java timer class ..
Also my application is web application using jsp,servlet and POJO file..
Here is my java class code...
public final class FetchMail extends TimerTask {
/** Construct and use a TimerTask and Timer. */
public static void main(String... arguments) {
TimerTask fetchMail = new FetchMail();
Timer timer = new Timer();
timer.scheduleAtFixedRate(fetchMail, getTomorrowMorning4am(), fONCE_PER_DAY);
}
/**
* Implements TimerTask's abstract run method.
*/
@Override
public void run() {
System.out.println("Fetching mail...");
}
private final static long fONCE_PER_DAY = 1000 * 60 * 60 * 24;
private static Date getTomorrowMorning4am() {
Calendar date = Calendar.getInstance();
date.set(
Calendar.DAY_OF_MONTH, 14);
date.set(Calendar.HOUR, 10);
date.set(Calendar.MINUTE, 14);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
return date.getTime();
}
}
Thanks in advance..