@@ -91,21 +91,24 @@ public static void main(String[] args) throws IOException {
9191 private static void sessionExpirationTask () {
9292 LOGGER .info ("Session expiration checker started..." );
9393 Instant currentTime = Instant .now ();
94- synchronized (sessions ) {
95- synchronized (sessionCreationTimes ) {
96- Iterator <Map .Entry <String , Instant >> iterator =
97- sessionCreationTimes .entrySet ().iterator ();
98- while (iterator .hasNext ()) {
99- Map .Entry <String , Instant > entry = iterator .next ();
100- if (entry .getValue ().plusMillis (SESSION_EXPIRATION_TIME ).isBefore (currentTime )) {
101- LOGGER .info ("User " + entry .getValue () + " removed" );
102- sessions .remove (entry .getKey ());
103- iterator .remove ();
94+ try {
95+ synchronized (sessions ) {
96+ synchronized (sessionCreationTimes ) {
97+ Iterator <Map .Entry <String , Instant >> iterator =
98+ sessionCreationTimes .entrySet ().iterator ();
99+ while (iterator .hasNext ()) {
100+ Map .Entry <String , Instant > entry = iterator .next ();
101+ if (entry .getValue ().plusMillis (SESSION_EXPIRATION_TIME ).isBefore (currentTime )) {
102+ LOGGER .info ("User " + entry .getValue () + " removed" );
103+ sessions .remove (entry .getKey ());
104+ iterator .remove ();
105+ }
104106 }
105107 }
106108 }
109+ } catch (Exception e ) {
110+ LOGGER .error ("An error occurred: " , e );
107111 }
108112 LOGGER .info ("Session expiration checker finished!" );
109113 }
110-
111114}
0 commit comments