[GLASSFISH-20673] TimerService createCalendarTimer with dayOfWeek Created: 30/Jun/13  Updated: 15/Nov/15  Resolved: 30/Jul/13

Status: Resolved
Project: glassfish
Component/s: ejb_container
Affects Version/s: 3.1.2_b23
Fix Version/s: None

Type: Bug Priority: Major
Reporter: rsoika Assignee: marina vatkina
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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



 Comments   
Comment by marina vatkina [ 01/Jul/13 ]

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

Comment by rsoika [ 02/Jul/13 ]

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?

Comment by marina vatkina [ 02/Jul/13 ]

[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

Comment by rsoika [ 06/Jul/13 ]

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??

Comment by rsoika [ 06/Jul/13 ]

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.

Comment by marina vatkina [ 08/Jul/13 ]

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?

Comment by rsoika [ 09/Jul/13 ]

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)

Comment by marina vatkina [ 09/Jul/13 ]

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?

Comment by rsoika [ 10/Jul/13 ]

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.

Comment by marina vatkina [ 10/Jul/13 ]

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

Comment by marina vatkina [ 30/Jul/13 ]

Please reopen if you have a reproducible test

Comment by black_unicorn [ 14/Oct/13 ]

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

Comment by romppu75 [ 15/Nov/15 ]

Hi!

I have exactly the same problem after two years!
How to reproduce:
1. Only on Sunday! (I have glassfish in production has exactly with same time settings, the server has been started on monday -> no problemm)
2. Create application with calendar timer (programatically or annotated), set dayOfWeek value to anything except *
3. Restart the server!

Timer event arises every second and getNextTimeout returns date in the past!!!

Comment by rsoika [ 15/Nov/15 ]

I tried to reopen a new bug report of this issue. Maybe we got some feedback.
https://java.net/jira/browse/GLASSFISH-21465

Generated at Tue Feb 09 20:45:24 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.