4

I have a java app deployed on an Amazon EC2 server. I use quartz for scheduling various jobs.

I tried scheduling a job to run at 9am - I noticed it didnt execute until 10am I then tried to execute a job at 9am GMT-5 -should of executed at 2pm GMT but it actually executed at 3pm GMT

On further analysis i noticed the time on my Amazon server was set in UTC and is an hour behind GMT currently

I was just wondering - what part of my setup is not currently correct since the jobs are not executing at the correct time?

Do I need to specify anything when setting the cron trigger? I am setting up the Cron in quartz as follows using the CronScheduleBuilder

    CronExpression cronExpression = new CronExpression(cronValue);
    TimeZone timeZone = TimeZone.getTimeZone("Etc/GMT-5");
     cronExpression.setTimeZone(timeZone);

     Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerName).startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();

        JobDetail job = JobBuilder.newJob(MyCloudTasksServerTaskExecutor.class).withIdentity(taskId.toString())
                .storeDurably(true).build();

Any help is greatly appreciated

Damien
  • 4,081
  • 12
  • 75
  • 126
  • 3
    Is it possible that the 1 hour difference is related to the Daylight Saving time? – Adam Ocsvari May 04 '15 at 16:37
  • Try set the time zone for the system {ec2 Instance} – Srinivasu May 05 '15 at 09:24
  • check this http://stackoverflow.com/questions/8812025/scheduling-a-job-on-aws-ec2?rq=1 – Abed Yaseen May 06 '15 at 03:41
  • 1
    In common use UTC and GMT are the same. Neither account for daylight saving. Don't confuse time zones (GMT+X, GMT-Y) with local names and/or daylight saving. Like it's currently 16:07 BST (British Summer Time = GMT+1) over here. – sysconfig May 07 '15 at 15:09

1 Answers1

3

As you wrote the EC2 server is running with UTC. GMT changed at the last Sunday of March from standard time to daylight saving time.

I would suggest to time all your jobs in UTC. Then the start time of the job is different in summer and winter. You have to decide if this is OK for you.

Else you have to create two timers, one running from March to October and the other from October to March which differ in one hour.

It is also logical that the EC2 instances run with UTC because then a shift across time zones is easier to achieve.

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48