| | |
| | | private static Thread onlinePollingThread; |
| | | |
| | | // 可配置的轮询参数(不再是final) |
| | | private static int cycleInterval = 60000; // 完整轮询周期间隔:60秒 |
| | | private static int slotInterval = 200; // 卡槽间查询间隔:200毫秒 |
| | | private static int cycleInterval = 120000; // 完整轮询周期间隔:60秒 |
| | | private static int slotInterval = 200; // 卡槽间查询间隔:500毫秒 |
| | | |
| | | // 卡槽相关常量 |
| | | private static final int MIN_SLOT = 1; |
| | |
| | | } else { |
| | | consecutiveFailures++; |
| | | if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) { |
| | | System.err.println("连续失败次数过多,暂停在线轮询"); |
| | | System.err.println("lunxunzaixian连续失败次数过多,暂停在线轮询"); |
| | | pauseOnlinePolling(); |
| | | } |
| | | } |
| | |
| | | int polledCount = 0; |
| | | int totalCardSlots = cardSlots.size(); |
| | | |
| | | // 第二阶段:批量查询有卡卡槽 |
| | | // 第二阶段:批量查询有卡卡槽 - 修复:每个卡槽间都有间隔 |
| | | for (int i = 0; i < cardSlots.size(); i += BATCH_SIZE) { |
| | | if (!isRunning.get() || Thread.currentThread().isInterrupted() || shouldStop.get()) { |
| | | break; |
| | |
| | | int end = Math.min(i + BATCH_SIZE, cardSlots.size()); |
| | | List<Integer> batch = cardSlots.subList(i, end); |
| | | |
| | | // 批次内查询 |
| | | for (int slotNumber : batch) { |
| | | // 批次内查询 - 修复:每个卡槽间添加间隔 |
| | | for (int j = 0; j < batch.size(); j++) { |
| | | int slotNumber = batch.get(j); |
| | | |
| | | if (sendQueryToCardSlot(slotNumber)) { |
| | | polledCount++; |
| | | } |
| | | |
| | | // 重要修复:每个卡槽查询后等待指定间隔(最后一个卡槽除外) |
| | | if (j < batch.size() - 1) { |
| | | try { |
| | | Thread.sleep(slotInterval); // 卡槽间间隔 |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 批次间间隔 |
| | | // 批次间间隔(保持原有逻辑) |
| | | if (end < cardSlots.size()) { |
| | | try { |
| | | Thread.sleep(slotInterval * BATCH_SIZE); |
| | |
| | | } |
| | | |
| | | if (polledCount > 0 && lunxun.DEBUG_ENABLED) { |
| | | //System.out.println("在线轮询完成,成功查询 " + polledCount + "/" + totalCardSlots + " 个有卡卡槽"); |
| | | System.out.println("在线轮询完成,成功查询 " + polledCount + "/" + totalCardSlots + " 个有卡卡槽"); |
| | | } |
| | | |
| | | return polledCount > 0; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 向指定有卡卡槽发送查询指令 |
| | | * @param slotNumber 卡槽编号 |