Execute jobs after JVM terminates

Is it possible to schedule jobs inside the JVM to run after the JVM terminates?

In my application, the user can choose to receive notifications of new emails in their mailboxes. I accomplished this with Quartz, with a job EmailChecker

that needs to run every 45 seconds.

public void checkInbox() throws SchedulerException
{
    JobDetail job = JobBuilder.newJob(EmailChecker.class)
            .withIdentity("emailJob", "jobGroup").build();

    Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity("emailTrigger", "jobGroup")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/45 * * * * ?"))
            .build();

    Scheduler scheduler = new StdSchedulerFactory().getScheduler();
    scheduler.start();
    scheduler.scheduleJob(job, trigger);

}

      

Everything works fine, but only when the JVM starts up. Once it is out, no more notification will be sent.

The application is a desktop application and therefore will not run permanently. And this feature would be very useless if it only worked in the JVM, as the user would also be able to view their inbox in real time, so notifications would be redundant.

+3


source to share


1 answer


Not inside the JVM, because once the JVM exits, it doesn't start to do the jobs. You can use a tool such as cron or at to schedule a new JVM. If you can leave JVM execution, you can use the JVM to schedule jobs (you could use something like quartz-scheduler ).



+3


source







All Articles