java - how to execute the code in the specific time using timertask -
hi listener class
public void contextinitialized(servletcontextevent arg0) { // todo auto-generated method stub system.out.println("inside listener context"); timer timer = new timer(); calendar cal = calendar.getinstance(); cal.set(calendar.hour_of_day, 19); cal.set(calendar.minute, 00); cal.set(calendar.second, 00); time sqltime4 = new time(cal.gettime().gettime()); timer.schedule(new mytimertask(),sqltime4);
}
this timertask class
package com.uttara.reg; import java.util.date; import java.util.timertask; public class timer extends timertask { @override public void run() { // todo auto-generated method stub system.out.println("inside run of timer"); } public void scheduleatfixedrate(timertask timertask, date executiondate, long period) { system.out.println("run"); // todo auto-generated method stub } }
that task not triggering in specific event,could plz rectify problem in it....
thanks in advance
multiple problems in code, here they:
- first of have picked confusing name timertask child class.
timer
class defined injava.util
package, used create scheduled task. - you creating anonymous class of type timertask used run scheduled task.
you can try change code this:
public void contextinitialized(servletcontextevent arg0) { // todo auto-generated method stub system.out.println("inside listener context"); timer timer = new timer(); date executiondate = new date(); long period = 24 * 60 * 60 * 1000; timer.scheduleatfixedrate(new mytimertask(), executiondate, period); }
mytimertask
package com.uttara.reg; import java.util.date; import java.util.timertask; public class mytimertask extends timertask { @override public void run() { // todo auto-generated method stub system.out.println("inside run of timer"); } public void scheduleatfixedrate(timertask timertask, date executiondate, long period) { system.out.println("run"); // todo auto-generated method stub } }
Comments
Post a Comment