| | |
| | | onlinePollingThread = new Thread(new OnlinePollingTask(), "Online-Polling-Thread"); |
| | | onlinePollingThread.setDaemon(true); |
| | | onlinePollingThread.start(); |
| | | System.out.println("在线轮询已启动,周期间隔: " + cycleInterval + "ms, 卡槽间隔: " + slotInterval + "ms"); |
| | | //System.out.println("在线轮询已启动,周期间隔: " + cycleInterval + "ms, 卡槽间隔: " + slotInterval + "ms"); |
| | | return true; |
| | | } catch (Exception e) { |
| | | System.err.println("启动在线轮询线程时发生异常: " + e.getMessage()); |
| | |
| | | */ |
| | | public static boolean stopOnlinePolling() { |
| | | if (!isRunning.get()) { |
| | | System.out.println("在线轮询未在运行"); |
| | | //System.out.println("在线轮询未在运行"); |
| | | return false; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | shouldStop.set(false); |
| | | System.out.println("在线轮询已停止"); |
| | | //System.out.println("在线轮询已停止"); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | public static boolean pauseOnlinePolling() { |
| | | if (!isRunning.get()) { |
| | | System.out.println("在线轮询未在运行,无法暂停"); |
| | | //System.out.println("在线轮询未在运行,无法暂停"); |
| | | return false; |
| | | } |
| | | |
| | | if (isPaused.get()) { |
| | | System.out.println("在线轮询已经处于暂停状态"); |
| | | //System.out.println("在线轮询已经处于暂停状态"); |
| | | return false; |
| | | } |
| | | |
| | | isPaused.set(true); |
| | | System.out.println("在线轮询已暂停"); |
| | | //System.out.println("在线轮询已暂停"); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | public static boolean resumeOnlinePolling() { |
| | | if (!isRunning.get()) { |
| | | System.out.println("在线轮询未在运行,无法恢复"); |
| | | //System.out.println("在线轮询未在运行,无法恢复"); |
| | | return false; |
| | | } |
| | | |
| | | if (!isPaused.get()) { |
| | | System.out.println("在线轮询未处于暂停状态"); |
| | | //System.out.println("在线轮询未处于暂停状态"); |
| | | return false; |
| | | } |
| | | |
| | |
| | | synchronized (lunxunzaixian.class) { |
| | | lunxunzaixian.class.notifyAll(); // 唤醒等待的线程 |
| | | } |
| | | System.out.println("在线轮询已恢复"); |
| | | //System.out.println("在线轮询已恢复"); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public static void setPollingIntervals(int cycleMs, int slotMs) { |
| | | cycleInterval = Math.max(cycleMs, 1000); // 最小1秒 |
| | | slotInterval = Math.max(slotMs, 50); // 最小50毫秒 |
| | | System.out.println("在线轮询间隔已设置 - 周期间隔: " + cycleInterval + "ms, 卡槽间隔: " + slotInterval + "ms"); |
| | | //System.out.println("在线轮询间隔已设置 - 周期间隔: " + cycleInterval + "ms, 卡槽间隔: " + slotInterval + "ms"); |
| | | |
| | | // 如果正在运行,重新启动以应用新的间隔 |
| | | if (isRunning.get()) { |
| | |
| | | private static class OnlinePollingTask implements Runnable { |
| | | @Override |
| | | public void run() { |
| | | System.out.println("在线轮询线程开始运行"); |
| | | //System.out.println("在线轮询线程开始运行"); |
| | | |
| | | while (isRunning.get() && !Thread.currentThread().isInterrupted() && !shouldStop.get()) { |
| | | try { |
| | |
| | | Thread.sleep(cycleInterval); |
| | | |
| | | } catch (InterruptedException e) { |
| | | System.out.println("在线轮询线程被中断"); |
| | | //System.out.println("在线轮询线程被中断"); |
| | | Thread.currentThread().interrupt(); |
| | | break; |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | } |
| | | |
| | | System.out.println("在线轮询线程结束运行"); |
| | | //System.out.println("在线轮询线程结束运行"); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | if (cardSlots.isEmpty()) { |
| | | if (lunxun.DEBUG_ENABLED) { |
| | | System.out.println("没有找到有卡的卡槽"); |
| | | //System.out.println("没有找到有卡的卡槽"); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | } |
| | | |
| | | if (polledCount > 0 && lunxun.DEBUG_ENABLED) { |
| | | System.out.println("在线轮询完成,成功查询 " + polledCount + "/" + totalCardSlots + " 个有卡卡槽"); |
| | | //System.out.println("在线轮询完成,成功查询 " + polledCount + "/" + totalCardSlots + " 个有卡卡槽"); |
| | | } |
| | | |
| | | return polledCount > 0; |
| | |
| | | if (result) { |
| | | // 记录调试信息(减少输出频率) |
| | | if (lunxun.DEBUG_ENABLED && (slotNumber == 1 || slotNumber % 10 == 0)) { |
| | | System.out.println("在线轮询 - 查询有卡卡槽 " + slotNumber); |
| | | //System.out.println("在线轮询 - 查询有卡卡槽 " + slotNumber); |
| | | } |
| | | return true; |
| | | } else { |
| | |
| | | return 0; |
| | | } |
| | | |
| | | System.out.println("开始立即轮询有卡卡槽..."); |
| | | //System.out.println("开始立即轮询有卡卡槽..."); |
| | | |
| | | OnlinePollingTask task = new OnlinePollingTask(); |
| | | |
| | |
| | | */ |
| | | public static boolean setOnlinePollingPaused(boolean paused) { |
| | | if (!isRunning.get()) { |
| | | System.out.println("在线轮询未在运行,无法设置暂停状态"); |
| | | //System.out.println("在线轮询未在运行,无法设置暂停状态"); |
| | | return false; |
| | | } |
| | | |