diff --git a/s3stream/src/main/java/com/automq/stream/s3/wal/benchmark/WriteBench.java b/s3stream/src/main/java/com/automq/stream/s3/wal/benchmark/WriteBench.java index 23c992e92..9a8c2084e 100644 --- a/s3stream/src/main/java/com/automq/stream/s3/wal/benchmark/WriteBench.java +++ b/s3stream/src/main/java/com/automq/stream/s3/wal/benchmark/WriteBench.java @@ -130,7 +130,7 @@ private void run(Config config) { config.threads, ThreadUtils.createThreadFactory("append-thread-%d", false), null); AppendTaskConfig appendTaskConfig = new AppendTaskConfig(config); Stat stat = new Stat(); - runTrimTask(); + Runnable stopTrim = runTrimTask(); for (int i = 0; i < config.threads; i++) { int index = i; executor.submit(() -> { @@ -152,11 +152,12 @@ private void run(Config config) { } catch (InterruptedException e) { executor.shutdownNow(); } + stopTrim.run(); System.out.println("Benchmark finished"); } - private void runTrimTask() { + private Runnable runTrimTask() { ScheduledExecutorService trimExecutor = Threads.newSingleThreadScheduledExecutor( ThreadUtils.createThreadFactory("trim-thread-%d", true), null); trimExecutor.scheduleAtFixedRate(() -> { @@ -167,6 +168,7 @@ private void runTrimTask() { e.printStackTrace(); } }, TRIM_INTERVAL_MILLIS, TRIM_INTERVAL_MILLIS, TimeUnit.MILLISECONDS); + return trimExecutor::shutdownNow; } private void runAppendTask(int index, AppendTaskConfig config, Stat stat) throws Exception {