Skip to content

Commit

Permalink
[ISSUE apache#251] Add shutdownHook to WindowAvg example
Browse files Browse the repository at this point in the history
  • Loading branch information
Jargon9 committed Feb 5, 2023
1 parent 61b081c commit 040a9df
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.nio.charset.StandardCharsets;
import java.time.LocalTime;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;

/**
* 1、启动RocketMQ
Expand Down Expand Up @@ -61,6 +62,22 @@ public static void main(String[] args) {

RocketMQStream rocketMQStream = new RocketMQStream(topologyBuilder, properties);

rocketMQStream.start();
final CountDownLatch latch = new CountDownLatch(1);

Runtime.getRuntime().addShutdownHook(new Thread("WindowAvg-shutdown-hook") {
@Override
public void run() {
rocketMQStream.stop();
latch.countDown();
}
});

try {
rocketMQStream.start();
latch.await();
} catch (final Throwable e) {
System.exit(1);
}
System.exit(0);
}
}

0 comments on commit 040a9df

Please sign in to comment.