glassfish
  1. glassfish
  2. GLASSFISH-20673

TimerService createCalendarTimer with dayOfWeek

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.1.2_b23
    • Fix Version/s: None
    • Component/s: ejb_container
    • Labels:
      None

      Description

      I tried to programmatic start a new calendar based timer service.
      I am setting the minute(), hour(), year(),.... based on my configuration.
      Everything works fine - until I try to set the 'dayOfWeek'

      When I use the following configuration:
      minute=15
      hour=20
      dayOfWeek=1-5

      ScheduleExpression scheduerExpression = new ScheduleExpression();
      scheduerExpression.minute("15");
      scheduerExpression.hour("20);
      scheduerExpression.dayOfWeek("1-5");
      Timer timer = timerService.createCalendarTimer(scheduerExpression,
      				timerConfig);
      

      The timer runs endless!
      When I ask the timer for the scheduler info I got the following toString() result:

      ScheduleExpression [second=0;minute=15;hour=20;dayOfMonth=*;month=*;dayOfWeek=15;year=*;timezoneID=CET;start=null;end=null]
      

      And when I ask timer.getNextTimeout() I got a date in the past!?
      I can not understand what is going wrong here

        Activity

        Hide
        marina vatkina added a comment -

        I can't reproduce it. This is the output that I got running it on Mon Jul 1 15:50:14 PDT 2013:

        [java] SCHEDULE: ScheduleExpression [second=0;minute=15;hour=20;dayOfMonth=*;month=*;dayOfWeek=1-5;year=*;timezoneID=null;start=null;end=null]
        [java] NEXT: Mon Jul 01 20:15:00 PDT 2013

        Show
        marina vatkina added a comment - I can't reproduce it. This is the output that I got running it on Mon Jul 1 15:50:14 PDT 2013: [java] SCHEDULE: ScheduleExpression [second=0;minute=15;hour=20;dayOfMonth=*;month=*;dayOfWeek=1-5;year=*;timezoneID=null;start=null;end=null] [java] NEXT: Mon Jul 01 20:15:00 PDT 2013
        Hide
        rsoika added a comment -

        Yes I confirm that it works fine again. I have tested it also yesterday (Mon) and today (Thu) and the scheduler works as expected.

        But I am absolutely sure, that the same code did not work if you start the Timer Service with that configuration on Sunday.
        I have also checked this with different timezone, but this seems not to be related. I am located in CET.

        Can you verify the behavior with a system time pointing to Sunday?

        Show
        rsoika added a comment - Yes I confirm that it works fine again. I have tested it also yesterday (Mon) and today (Thu) and the scheduler works as expected. But I am absolutely sure, that the same code did not work if you start the Timer Service with that configuration on Sunday. I have also checked this with different timezone, but this seems not to be related. I am located in CET. Can you verify the behavior with a system time pointing to Sunday?
        Hide
        marina vatkina added a comment -

        [java] SCHEDULE: ScheduleExpression [second=0;minute=15;hour=20;dayOfMonth=*;month=*;dayOfWeek=1-5;year=*;timezoneID=null;start=null;end=null]
        [java] NEXT: Mon Jul 01 20:15:00 PDT 2013

        Can you try on GF 4.0 or in a different Locale? In some Locales JDK Calendar calculated the next timeout wrong and I changed the code to always use Locale.ENGLISH- see GLASSFISH-18804

        Show
        marina vatkina added a comment - [java] SCHEDULE: ScheduleExpression [second=0;minute=15;hour=20;dayOfMonth=*;month=*;dayOfWeek=1-5;year=*;timezoneID=null;start=null;end=null] [java] NEXT: Mon Jul 01 20:15:00 PDT 2013 Can you try on GF 4.0 or in a different Locale? In some Locales JDK Calendar calculated the next timeout wrong and I changed the code to always use Locale.ENGLISH- see GLASSFISH-18804
        Hide
        rsoika added a comment -

        I can not test it on GlassFish4 for the moment.

        But I have verified the behavior again in GlassFish 3.1.2.2.
        And I think this is a problem.

        Just adjust your system time to Sunday and restart a TimerService with dayOfWeek=1-5.
        You will see that the timer runs endless. Isn't that a critical bug??

        Show
        rsoika added a comment - I can not test it on GlassFish4 for the moment. But I have verified the behavior again in GlassFish 3.1.2.2. And I think this is a problem. Just adjust your system time to Sunday and restart a TimerService with dayOfWeek=1-5. You will see that the timer runs endless. Isn't that a critical bug??
        Hide
        rsoika added a comment -

        The issue I described here is not related to GLASSFISH-18804

        The timer service have to be set to 'dayOfWeek=1-5' and be started on Sunday.

        Show
        rsoika added a comment - The issue I described here is not related to GLASSFISH-18804 The timer service have to be set to 'dayOfWeek=1-5' and be started on Sunday.
        Hide
        marina vatkina added a comment -

        I can't reproduce it on 3.1.x when set the current date to Sun Jul 7 15:28:23 PDT 2013:

        [java] SCHEDULE: ScheduleExpression [second=0;minute=15;hour=20;dayOfMonth=*;month=*;dayOfWeek=1-5;year=*;timezoneID=null;start=null;end=null]
        [java] NEXT: Mon Jul 08 20:15:00 PDT 2013

        Which locale are you on?

        Show
        marina vatkina added a comment - I can't reproduce it on 3.1.x when set the current date to Sun Jul 7 15:28:23 PDT 2013: [java] SCHEDULE: ScheduleExpression [second=0;minute=15;hour=20;dayOfMonth=*;month=*;dayOfWeek=1-5;year=*;timezoneID=null;start=null;end=null] [java] NEXT: Mon Jul 08 20:15:00 PDT 2013 Which locale are you on?
        Hide
        rsoika added a comment -

        My locale is DE_de. Time zone CET.
        I am using

        OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-1ubuntu1)
        OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

        Show
        rsoika added a comment - My locale is DE_de. Time zone CET. I am using OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-1ubuntu1) OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
        Hide
        marina vatkina added a comment -

        I tested the DE_de locale on my mac and it's also fine:

        INFO: dayOfWeek 1-5 in de_DE starts with 2013.07.08 20:15

        May be something else is off?

        Show
        marina vatkina added a comment - I tested the DE_de locale on my mac and it's also fine: INFO: dayOfWeek 1-5 in de_DE starts with 2013.07.08 20:15 May be something else is off?
        Hide
        rsoika added a comment -

        Thanks for your tests.
        Ok I will check this again.
        But believe me, in my test scenarios the computed scheduled date was in the past. That was really strange.

        Show
        rsoika added a comment - Thanks for your tests. Ok I will check this again. But believe me, in my test scenarios the computed scheduled date was in the past . That was really strange.
        Hide
        marina vatkina added a comment -

        I believe you. But to fix anything I need a reproducible condition.

        Show
        marina vatkina added a comment - I believe you. But to fix anything I need a reproducible condition.
        Hide
        marina vatkina added a comment -

        Please reopen if you have a reproducible test

        Show
        marina vatkina added a comment - Please reopen if you have a reproducible test
        Hide
        black_unicorn added a comment - - edited

        I have de same Problem.
        Now is Sunday in my Country.

        My code:

        ...
        ...
        ...
        ...
        ...
        @Startup
        @Singleton
        public class RiegoAutomatico {

        @Resource
        TimerService timerService;
        private Timer timer;
        private Timer timer2;
        private String dias;
        private String hora;
        private String minuto;
        private String intervaloMonitoreoHoras;
        @EJB
        private GestorDeConfiguracionDelNodo gdcdn;
        @EJB
        private GestorDeConfiguracionDeRiegoAgendado gdcdra;
        ...
        ...
        ...
        ...

        public void setTimerDeRiegoAutomatico()

        { //this.dias contains "Tue,Sun" //this.hora contains "7" //this.minuto contains "0" timer = timerService.createCalendarTimer(new ScheduleExpression().dayOfWeek(this.dias).hour(this.hora).minute(this.minuto), new TimerConfig("RiegoAutomatico", true)); System.out.println("Riego Automático agendado como: " + timer.getSchedule().toString()); System.out.println("Riego Automático calendar: " + Calendar.getInstance()); System.out.println("Riego Automático Locale.getDefault().getCountry(): " + Locale.getDefault().getCountry()); System.out.println("Riego Automático Locale.getDefault().getDisplayCountry(): " + Locale.getDefault().getDisplayCountry()); System.out.println("Riego Automático Locale.getDefault().getDisplayLanguage(): " + Locale.getDefault().getDisplayLanguage()); System.out.println("Riego Automático Locale.getDefault().getDisplayName(): " + Locale.getDefault().getDisplayName()); System.out.println("Riego Automático Locale.getDefault().getDisplayVariant(): " + Locale.getDefault().getDisplayVariant()); System.out.println("Riego Automático Locale.getDefault().getISO3Country(): " + Locale.getDefault().getISO3Country()); System.out.println("Riego Automático Locale.getDefault().getISO3Language(): " + Locale.getDefault().getISO3Language()); System.out.println("Riego Automático Locale.getDefault().getLanguage(): " + Locale.getDefault().getLanguage()); System.out.println("Riego Automático Locale.getDefault().getVariant(): " + Locale.getDefault().getVariant()); System.out.println("Riego Automático timer.getNextTimeout()" + timer.getNextTimeout()); System.out.println("Riego Automático timer.getHandle().getTimer().toString(): " + timer.getHandle().getTimer().toString()); //this.intervaloMonitoreoHoras contains "1" timer2 = timerService.createCalendarTimer(new ScheduleExpression().dayOfWeek("*").hour(this.intervaloMonitoreoHoras), new TimerConfig("RiegoMixto", true)); }

        My Output:
        ...
        Launching GlassFish on Felix platform
        Running GlassFish Version: GlassFish Server Open Source Edition 3.1.2 (build 23)
        ...
        ...
        ...

        INFO: Riego Automático agendado como: ScheduleExpression [second=0;minute=0;hour=7;dayOfMonth=*;month=*;dayOfWeek=Tue,Sun;year=*;timezoneID=null;start=null;end=null] <--- This timer is fine (don't runs endless)

        INFO: Riego Automático calendar: java.util.GregorianCalendar[time=1381713382872,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Montevideo",offset=-10800000,dstSavings=3600000,useDaylight=true,transitions=132,lastRule=java.util.SimpleTimeZone[id=America/Montevideo,offset=-10800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=9,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=2,endDay=8,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=2,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=9,WEEK_OF_YEAR=41,WEEK_OF_MONTH=2,DAY_OF_MONTH=13,DAY_OF_YEAR=286,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=16,SECOND=22,MILLISECOND=872,ZONE_OFFSET=-10800000,DST_OFFSET=3600000]

        INFO: Riego Automático Locale.getDefault().getCountry(): UY
        INFO: Riego Automático Locale.getDefault().getDisplayCountry(): Uruguay
        INFO: Riego Automático Locale.getDefault().getDisplayLanguage(): español
        INFO: Riego Automático Locale.getDefault().getDisplayName(): español (Uruguay)
        INFO: Riego Automático Locale.getDefault().getDisplayVariant():
        INFO: Riego Automático Locale.getDefault().getISO3Country(): URY
        INFO: Riego Automático Locale.getDefault().getISO3Language(): spa
        INFO: Riego Automático Locale.getDefault().getLanguage(): es
        INFO: Riego Automático Locale.getDefault().getVariant():

        INFO: Riego Automático timer.getNextTimeout()Tue Oct 15 07:00:00 UYST 2013

        INFO: Riego Automático timer.getHandle().getTimer().toString(): Timer 10@@1381713317699@@server@@domain1
        ...
        ...
        ...
        ScheduleExpression [second=0;minute=0;hour=*/1;dayOfMonth=*;month=*;dayOfWeek=*;year=*;timezoneID=null;start=null;end=null]|#] <--- This timer is fine (don't runs endless)
        ...
        ...

        /********************************************************************************************/
        Now when I change the content of the variable //this.dias with "Tue,Sat"
        /********************************************************************************************/

        ...
        Launching GlassFish on Felix platform
        Running GlassFish Version: GlassFish Server Open Source Edition 3.1.2 (build 23)
        ...
        ...
        ...

        INFO: Riego Automático agendado como: ScheduleExpression [second=0;minute=0;hour=7;dayOfMonth=*;month=*;dayOfWeek=Tue,Sat;year=*;timezoneID=null;start=null;end=null] <--- This timer isn't fine (starts runs endless!!!!)

        INFO: Riego Automático calendar: java.util.GregorianCalendar[time=1381713555852,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Montevideo",offset=-10800000,dstSavings=3600000,useDaylight=true,transitions=132,lastRule=java.util.SimpleTimeZone[id=America/Montevideo,offset=-10800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=9,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=2,endDay=8,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=2,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=9,WEEK_OF_YEAR=41,WEEK_OF_MONTH=2,DAY_OF_MONTH=13,DAY_OF_YEAR=286,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=19,SECOND=15,MILLISECOND=852,ZONE_OFFSET=-10800000,DST_OFFSET=3600000]

        INFO: Riego Automático Locale.getDefault().getCountry(): UY
        INFO: Riego Automático Locale.getDefault().getDisplayCountry(): Uruguay
        INFO: Riego Automático Locale.getDefault().getDisplayLanguage(): español
        INFO: Riego Automático Locale.getDefault().getDisplayName(): español (Uruguay)
        INFO: Riego Automático Locale.getDefault().getDisplayVariant():
        INFO: Riego Automático Locale.getDefault().getISO3Country(): URY
        INFO: Riego Automático Locale.getDefault().getISO3Language(): spa
        INFO: Riego Automático Locale.getDefault().getLanguage(): es
        INFO: Riego Automático Locale.getDefault().getVariant():

        INFO: Riego Automático timer.getNextTimeout()Tue Oct 08 07:00:00 UYST 2013

        INFO: Riego Automático timer.getHandle().getTimer().toString(): Timer 11@@1381713317699@@server@@domain1

        ...
        ...
        ...
        ScheduleExpression [second=0;minute=0;hour=*/1;dayOfMonth=*;month=*;dayOfWeek=*;year=*;timezoneID=null;start=null;end=null]|#] <--- This timer is fine (don't runs endless)

        Note, Environment:
        Windows 7 x64 and x86
        GlassFish Server Open Source Edition 3.1.2 (build 23)
        JDK 1.6.0_20-b02 and 1.7.0_21-b11

        Show
        black_unicorn added a comment - - edited I have de same Problem. Now is Sunday in my Country. My code: ... ... ... ... ... @Startup @Singleton public class RiegoAutomatico { @Resource TimerService timerService; private Timer timer; private Timer timer2; private String dias; private String hora; private String minuto; private String intervaloMonitoreoHoras; @EJB private GestorDeConfiguracionDelNodo gdcdn; @EJB private GestorDeConfiguracionDeRiegoAgendado gdcdra; ... ... ... ... public void setTimerDeRiegoAutomatico() { //this.dias contains "Tue,Sun" //this.hora contains "7" //this.minuto contains "0" timer = timerService.createCalendarTimer(new ScheduleExpression().dayOfWeek(this.dias).hour(this.hora).minute(this.minuto), new TimerConfig("RiegoAutomatico", true)); System.out.println("Riego Automático agendado como: " + timer.getSchedule().toString()); System.out.println("Riego Automático calendar: " + Calendar.getInstance()); System.out.println("Riego Automático Locale.getDefault().getCountry(): " + Locale.getDefault().getCountry()); System.out.println("Riego Automático Locale.getDefault().getDisplayCountry(): " + Locale.getDefault().getDisplayCountry()); System.out.println("Riego Automático Locale.getDefault().getDisplayLanguage(): " + Locale.getDefault().getDisplayLanguage()); System.out.println("Riego Automático Locale.getDefault().getDisplayName(): " + Locale.getDefault().getDisplayName()); System.out.println("Riego Automático Locale.getDefault().getDisplayVariant(): " + Locale.getDefault().getDisplayVariant()); System.out.println("Riego Automático Locale.getDefault().getISO3Country(): " + Locale.getDefault().getISO3Country()); System.out.println("Riego Automático Locale.getDefault().getISO3Language(): " + Locale.getDefault().getISO3Language()); System.out.println("Riego Automático Locale.getDefault().getLanguage(): " + Locale.getDefault().getLanguage()); System.out.println("Riego Automático Locale.getDefault().getVariant(): " + Locale.getDefault().getVariant()); System.out.println("Riego Automático timer.getNextTimeout()" + timer.getNextTimeout()); System.out.println("Riego Automático timer.getHandle().getTimer().toString(): " + timer.getHandle().getTimer().toString()); //this.intervaloMonitoreoHoras contains "1" timer2 = timerService.createCalendarTimer(new ScheduleExpression().dayOfWeek("*").hour(this.intervaloMonitoreoHoras), new TimerConfig("RiegoMixto", true)); } My Output: ... Launching GlassFish on Felix platform Running GlassFish Version: GlassFish Server Open Source Edition 3.1.2 (build 23) ... ... ... INFO: Riego Automático agendado como: ScheduleExpression [second=0;minute=0;hour=7;dayOfMonth=*;month=*;dayOfWeek=Tue,Sun;year=*;timezoneID=null;start=null;end=null] <--- This timer is fine (don't runs endless) INFO: Riego Automático calendar: java.util.GregorianCalendar[time=1381713382872,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Montevideo",offset=-10800000,dstSavings=3600000,useDaylight=true,transitions=132,lastRule=java.util.SimpleTimeZone [id=America/Montevideo,offset=-10800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=9,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=2,endDay=8,endDayOfWeek=1,endTime=7200000,endTimeMode=0] ],firstDayOfWeek=2,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=9,WEEK_OF_YEAR=41,WEEK_OF_MONTH=2,DAY_OF_MONTH=13,DAY_OF_YEAR=286,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=16,SECOND=22,MILLISECOND=872,ZONE_OFFSET=-10800000,DST_OFFSET=3600000] INFO: Riego Automático Locale.getDefault().getCountry(): UY INFO: Riego Automático Locale.getDefault().getDisplayCountry(): Uruguay INFO: Riego Automático Locale.getDefault().getDisplayLanguage(): español INFO: Riego Automático Locale.getDefault().getDisplayName(): español (Uruguay) INFO: Riego Automático Locale.getDefault().getDisplayVariant(): INFO: Riego Automático Locale.getDefault().getISO3Country(): URY INFO: Riego Automático Locale.getDefault().getISO3Language(): spa INFO: Riego Automático Locale.getDefault().getLanguage(): es INFO: Riego Automático Locale.getDefault().getVariant(): INFO: Riego Automático timer.getNextTimeout()Tue Oct 15 07:00:00 UYST 2013 INFO: Riego Automático timer.getHandle().getTimer().toString(): Timer 10@@1381713317699@@server@@domain1 ... ... ... ScheduleExpression [second=0;minute=0;hour=*/1;dayOfMonth=*;month=*;dayOfWeek=*;year=*;timezoneID=null;start=null;end=null] |#] <--- This timer is fine (don't runs endless) ... ... /********************************************************************************************/ Now when I change the content of the variable //this.dias with "Tue,Sat" /********************************************************************************************/ ... Launching GlassFish on Felix platform Running GlassFish Version: GlassFish Server Open Source Edition 3.1.2 (build 23) ... ... ... INFO: Riego Automático agendado como: ScheduleExpression [second=0;minute=0;hour=7;dayOfMonth=*;month=*;dayOfWeek=Tue,Sat;year=*;timezoneID=null;start=null;end=null] <--- This timer isn't fine (starts runs endless!!!!) INFO: Riego Automático calendar: java.util.GregorianCalendar[time=1381713555852,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Montevideo",offset=-10800000,dstSavings=3600000,useDaylight=true,transitions=132,lastRule=java.util.SimpleTimeZone [id=America/Montevideo,offset=-10800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=9,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=2,endDay=8,endDayOfWeek=1,endTime=7200000,endTimeMode=0] ],firstDayOfWeek=2,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=9,WEEK_OF_YEAR=41,WEEK_OF_MONTH=2,DAY_OF_MONTH=13,DAY_OF_YEAR=286,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=19,SECOND=15,MILLISECOND=852,ZONE_OFFSET=-10800000,DST_OFFSET=3600000] INFO: Riego Automático Locale.getDefault().getCountry(): UY INFO: Riego Automático Locale.getDefault().getDisplayCountry(): Uruguay INFO: Riego Automático Locale.getDefault().getDisplayLanguage(): español INFO: Riego Automático Locale.getDefault().getDisplayName(): español (Uruguay) INFO: Riego Automático Locale.getDefault().getDisplayVariant(): INFO: Riego Automático Locale.getDefault().getISO3Country(): URY INFO: Riego Automático Locale.getDefault().getISO3Language(): spa INFO: Riego Automático Locale.getDefault().getLanguage(): es INFO: Riego Automático Locale.getDefault().getVariant(): INFO: Riego Automático timer.getNextTimeout()Tue Oct 08 07:00:00 UYST 2013 INFO: Riego Automático timer.getHandle().getTimer().toString(): Timer 11@@1381713317699@@server@@domain1 ... ... ... ScheduleExpression [second=0;minute=0;hour=*/1;dayOfMonth=*;month=*;dayOfWeek=*;year=*;timezoneID=null;start=null;end=null] |#] <--- This timer is fine (don't runs endless) Note, Environment: Windows 7 x64 and x86 GlassFish Server Open Source Edition 3.1.2 (build 23) JDK 1.6.0_20-b02 and 1.7.0_21-b11

          People

          • Assignee:
            marina vatkina
            Reporter:
            rsoika
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: