我说的是Thread实例,如果它们将Runnable作为构造函数参数提供,而您只能执行它们的start方法一次,那么Executor*类家族为什么要重用它们呢?
PS:我知道并使用了Executor类,这些类比裸线程抽象得更好,我只是出于好奇而问这个问题。
发布于 2013-04-21 06:02:52
传递给executor线程的runnables (让我们称之为R)实际上包装在其他runnables (让我们称它们为W)中。W的run()方法的伪代码是
while (threadMustRun) {
wait for new R to be submitted and assigned to this thread
execute R.run()
}它实际上比这复杂得多,但你应该明白这一点。要真正理解它的作用,请查看ThreadPoolExecutor.Worker内部类的代码。
https://stackoverflow.com/questions/16125602
复制相似问题