代码之家  ›  专栏  ›  技术社区  ›  hemu

ScheduledExecutorService-任务scheduleAtFixedRate停止运行

  •  0
  • hemu  · 技术社区  · 4 年前

       // List of active sessions Id for which need to send ping
        private List<Long> activeSessionIds = new ArrayList<>(); 
        
        sessionKeepAliveTask = scheduledExecutorService.scheduleAtFixedRate(() -> {
                    log.info("Sending ping for all active sessions");
                    var t1 = System.currentTimeMillis();
                    this.activeSessionIds.forEach((sessionId) -> {
                        try {
                            this.sendKeepalive(sessionId);
                        } catch (Exception e) {
                            log.error("Error occurred while sending ping for session: {}", sessionId);
                        }
                    });
                    var t2 = System.currentTimeMillis();
                    log.info("Time taken for sending ping for {} sessions: {}", activeSessionIds.size(), (t2-t1));
                }, 1L, 25, TimeUnit.SECONDS);
    

    中的值 activeSessionIds

    你知道我在这里遗漏了什么吗?

    0 回复  |  直到 4 年前