How to kill CompletableFuture related threads?

后端 未结 2 1897
-上瘾入骨i
-上瘾入骨i 2021-01-07 06:16

I have method that is checking the CompletableFuture execution time. If such CompletableFuture is executing for more than 2 seconds i want to kill this task. But how can I d

2条回答
  •  再見小時候
    2021-01-07 07:13

    The only way to terminate a thread is via interruption, which is a cooperative mechanism. This means the the thread must implement interruption logic, by handling the InterruptedException.

    But it is a really bad practice to interrupt threads that you don't own, which I think is your case.

提交回复
热议问题