Module java.base

Interface RejectedExecutionHandler

所有已知的实现类:
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy

public interface RejectedExecutionHandler
无法由 ThreadPoolExecutor 执行的任务的处理程序。
自 JDK 版本:
1.5
  • Method Details

    • rejectedExecution

      void rejectedExecution(Runnable r, ThreadPoolExecutor executor)
      ThreadPoolExecutor 无法接受任务时,可能会被 ThreadPoolExecutor 调用的方法。当没有更多线程或队列槽可用时,因为它们的边界将被超出,或者在执行器关闭时可能会发生这种情况。

      在没有其他选择的情况下,该方法可能会抛出一个未经检查的 RejectedExecutionException,该异常将传播给 execute 的调用者。

      参数:
      r - 请求执行的可运行任务
      executor - 尝试执行此任务的执行器
      抛出:
      RejectedExecutionException - 如果没有补救措施