private void restartConnectionLostTimer ( ) { cancelConnectionLostTimer ( ) ; connectionLostCheckerService = Executors . newSingleThreadScheduledExecutor ( new NamedThreadFactory ( "connectionLostChecker" ) ) ; Runnable connectionLostChecker = new Runnable ( ) { /** * Keep the connections in a separate list to not cause deadlocks */ private ArrayList < WebSocket > connections = new ArrayList < WebSocket > ( ) ; @ Override public void run ( ) { connections . clear ( ) ; try { connections . addAll ( getConnections ( ) ) ; long minimumPongTime = ( long ) ( System . nanoTime ( ) - ( connectionLostTimeout * 1.5 ) ) ; for ( WebSocket conn : connections ) { executeConnectionLostDetection ( conn , minimumPongTime ) ; } } catch ( Exception e ) { //Ignore this exception } connections . clear ( ) ; } } ; connectionLostCheckerFuture = connectionLostCheckerService . scheduleAtFixedRate ( connectionLostChecker , connectionLostTimeout , connectionLostTimeout , TimeUnit . NANOSECONDS ) ; }
This methods allows the reset of the connection lost timer in case of a changed parameter