kafka使用经验

2020-03-15  本文已影响0人  知而乐者
// 判断是否已经关闭
        AtomicBoolean isRunning = new AtomicBoolean(true);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    isRunning.compareAndSet(true, false);
                    shutdownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }));
        while (isRunning.get()) {
        //执行代码
        //
            consumer.commitSync();
        }
        shutdownLatch.countDown();
}
上一篇 下一篇

猜你喜欢

热点阅读