문제

I have a ServletContextListener which is executing on every 5 seconds.Now as per my need i have to set it to execute on 10th date of every month at 10 am.But i am not able to set it..

Here is my code..

@WebListener()
public class MyContext implements ServletContextListener {

private ScheduledExecutorService sched;

@Override
public void contextInitialized(ServletContextEvent event) {
    sched = Executors.newSingleThreadScheduledExecutor();
    sched.scheduleAtFixedRate(new MyTask(), 0, 5, TimeUnit.SECONDS);
}

@Override
public void contextDestroyed(ServletContextEvent event) {
    sched.shutdownNow();
}
}

new MyTask() is the class that is called to excute.

Here is my timer code to run on particular schedule..

Timer timer = new Timer();
    Calendar date = Calendar.getInstance();
    date.set(
            Calendar.DAY_OF_WEEK,
            Calendar.TUESDAY);
    date.set(Calendar.HOUR, 11);
    date.set(Calendar.MINUTE, 51);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);


    timer.schedule(
            new ReportGenerator(),
            date.getTime(),
            1000 * 60 * 60 * 24 * 7);

Please help me .. Thanks in advance..

도움이 되었습니까?

해결책

You should use @Schedule of Timer Service of EJB or Quartz.

@Schedule(....)

For details, read this tutorial

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top