@@ -41,10 +41,17 @@ public class DefaultSessionSchedule implements SessionSchedule {
4141 private final int [] weekdayOffsets ;
4242 protected static final Logger LOG = LoggerFactory .getLogger (DefaultSessionSchedule .class );
4343
44+ //Cache recent time data to reduce creation of calendar objects
45+ private final ThreadLocal <Calendar > threadLocalCalendar ;
46+ private final ThreadLocal <TimeInterval > threadLocalRecentTimeInterval ;
47+
4448 public DefaultSessionSchedule (SessionSettings settings , SessionID sessionID ) throws ConfigError ,
4549 FieldConvertError {
50+ threadLocalCalendar = ThreadLocal .withInitial (SystemTime ::getUtcCalendar );
51+ threadLocalRecentTimeInterval = new ThreadLocal <>();
52+ isNonStopSession = settings .isSetting (sessionID , Session .SETTING_NON_STOP_SESSION )
53+ && settings .getBool (sessionID , Session .SETTING_NON_STOP_SESSION );
4654
47- isNonStopSession = settings .isSetting (sessionID , Session .SETTING_NON_STOP_SESSION ) && settings .getBool (sessionID , Session .SETTING_NON_STOP_SESSION );
4855 TimeZone defaultTimeZone = getDefaultTimeZone (settings , sessionID );
4956 if (isNonStopSession ) {
5057 isWeekdaySession = false ;
@@ -104,7 +111,7 @@ private TimeEndPoint getTimeEndPoint(SessionSettings settings, SessionID session
104111 }
105112
106113 private TimeZone getDefaultTimeZone (SessionSettings settings , SessionID sessionID )
107- throws ConfigError , FieldConvertError {
114+ throws ConfigError {
108115 TimeZone sessionTimeZone ;
109116 if (settings .isSetting (sessionID , Session .SETTING_TIMEZONE )) {
110117 String sessionTimeZoneID = settings .getString (sessionID , Session .SETTING_TIMEZONE );
@@ -300,9 +307,16 @@ public boolean isSessionTime() {
300307 if (isNonStopSession ()) {
301308 return true ;
302309 }
303- Calendar now = SystemTime .getUtcCalendar ();
304- TimeInterval interval = theMostRecentIntervalBefore (now );
305- return interval .isContainingTime (now );
310+ Calendar now = threadLocalCalendar .get ();
311+ now .setTimeInMillis (SystemTime .currentTimeMillis ());
312+ TimeInterval mostRecentInterval = threadLocalRecentTimeInterval .get ();
313+ if (mostRecentInterval != null && mostRecentInterval .isContainingTime (now )) {
314+ return true ;
315+ }
316+ mostRecentInterval = theMostRecentIntervalBefore (now );
317+ boolean result = mostRecentInterval .isContainingTime (now );
318+ threadLocalRecentTimeInterval .set (mostRecentInterval );
319+ return result ;
306320 }
307321
308322 public String toString () {
0 commit comments