1

From the Quartz Scheduler javadocs for the method setTimeZone of class CronTrigger:

If setCronExpression(CronExpression) is called after this method, the TimeZone setting on the CronExpression will "win". However if setCronExpression(String) is called after this method, the time zone applied by this method will remain in effect, since the String cron expression does not carry a time zone!

What's the difference in calling both setters in different sequences?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
craftsman
  • 15,133
  • 17
  • 70
  • 86

2 Answers2

2

What this means is that if you call setCronExpression(CronExpression) when you have already set a TimeZone using setTimeZone, the TimeZone you specified will be overwritten by the CronExpression's TimeZone. This is because the CronExpression class contains a TimeZone.

However, the String cron expression does not contain any time zone information - therefore the time zone you specified in setTimeZone will remain in effect.

Does that make sense?

  • Thank you for the effort Phill, I got the point now :) But the samG's answer was easier for me to understand! – craftsman Jul 26 '10 at 08:06
1

There are three scenarios-

  1. You call setTimeZone() followed by setCronExpression(CronExpression). The time zone associated with the CronExpression will apply.

  2. You call setTimeZone() followed by setCronExpression(String). The time zone specified by setTimeZone() will apply since the String cron expression doesn't have a time zone associated.

  3. You call setCronExpression(CronExpression) or setCronExpression(String) followed by setTimeZone(). The time zone specified by setTimeZone() method will apply.

samitgaur
  • 5,601
  • 2
  • 29
  • 33