Skip to content

Commit

Permalink
Merge pull request #516 from KamToHung/fix-515
Browse files Browse the repository at this point in the history
[ISSUE #515] add scheduledFuture cancel check
  • Loading branch information
yanhom1314 authored Dec 16, 2024
2 parents 8f585de + 9704b33 commit 7e88a92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static void tryPrintError(Runnable r, Throwable t) {
if (r instanceof FutureTask) {
try {
FutureTask<?> future = (FutureTask<?>) r;
if (future.isDone()) {
if (future.isDone() && !future.isCancelled()) {
future.get();
}
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.time.LocalDateTime;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

@PropertySource(value = "classpath:/dynamic-tp-nacos-demo-dtp-dev.yml", factory = YamlPropertySourceFactory.class)
Expand Down Expand Up @@ -67,4 +68,14 @@ void testSubNotify() {
dtpExecutor14.shutdownNow();
}

@Test
void testScheduleCancel() {
ScheduledDtpExecutor dtpExecutor12 = (ScheduledDtpExecutor) DtpRegistry.getExecutor("dtpExecutor12");
ScheduledFuture<?> scheduledFuture = dtpExecutor12.scheduleWithFixedDelay(() -> {
System.out.println(Thread.currentThread().getName() + "进来了," +
"当前时间是 ");
}, 0, 1000, TimeUnit.MILLISECONDS);
scheduledFuture.cancel(false);
}

}

0 comments on commit 7e88a92

Please sign in to comment.