【问题标题】:Java the parameters in beforeExecute() of ThreadPoolExecutor classJava ThreadPoolExecutor 类的 beforeExecute() 中的参数
【发布时间】:2018-01-01 10:07:25
【问题描述】:

ThreadPoolExecutor类中beforeExecute()的参数是ThreadRunnable

有时我们可能需要重写此方法以满足我们的需求。

但是,当我在 executor 中提交一些 可调用 任务时。这里beforeExecute()中我们只能得到Runnable对象,所以不知道executor是不是隐式的将callable form转换为runnable???

我在Executors 类中找到了一些实用方法,它们将Runnable 转换为Callable,但我没有找到相反的方法。

【问题讨论】:

    标签: java multithreading executor


    【解决方案1】:

    调用submit(Callable) 调用newTaskFor(),它返回一个调用Callable 的Runnable。然后将该 Runnable 传递给execute()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多