How are tasks in the java thread pool timed?

if I start my own thread, I usually write

.

t.join(2000)
t..interrupt();

after using ThreadPoolExecutor to execute a task, I don"t know how to force a task that has timed out to stop.

Mar.23,2021

one solution is to use a get method in FutureTask, with the parameter timeout. If the execution time exceeds timeout, and throws TimeoutException, you can catch it for processing

Menu