2 分钟写了个案例,如果要更精细用 nanoTime ```java int MAX_CNT_OF_SEC = 100; int count = 0; long lastPoll = -1l; long ONE_SEC = Duration.ofSeconds(1L).toMillis(); while (true) { long now = System.currentTimeMillis(); long diff = now - lastPoll; if (diff < ONE_SEC || count >= MAX_CNT_OF_SEC) { Thread.sleep(ONE_SEC - diff); }
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));