@@ -54,6 +54,7 @@ public static void main(String[] args) {
5454
5555 private final ExecutorService executor ;
5656 private final AtomicInteger threadCounter = new AtomicInteger (0 );
57+ private volatile boolean isStopped = false ;
5758
5859 public Application (Config config , SchemeService schemeService , TokenService tokenService , MeterRegistry registry ) {
5960 this .config = config ;
@@ -66,6 +67,7 @@ public Application(Config config, SchemeService schemeService, TokenService toke
6667
6768 @ PreDestroy
6869 public void close () throws Exception {
70+ isStopped = true ;
6971 logger .info ("CLI app is waiting for finishing" );
7072
7173 executor .shutdown ();
@@ -131,6 +133,10 @@ private void loadData() {
131133 final int last = id < recordsCount ? id : recordsCount ;
132134
133135 futures .add (CompletableFuture .runAsync (() -> {
136+ if (isStopped ) {
137+ return ;
138+ }
139+
134140 ticker .getLoad ().measure (() -> {
135141 tokenService .insertBatch (first , last );
136142 logger .debug ("inserted tokens [{}, {})" , first , last );
@@ -168,7 +174,7 @@ private void workload(RateLimiter rt, long finishAt) {
168174 final Random rnd = new Random ();
169175 final int recordCount = config .getRecordsCount ();
170176
171- while (System .currentTimeMillis () < finishAt ) {
177+ while (( System .currentTimeMillis () < finishAt ) && ! isStopped ) {
172178 rt .acquire ();
173179 int mode = rnd .nextInt (10 );
174180
0 commit comments