java.util.concurrent.Executor如何工作? [英] How does java.util.concurrent.Executor work?
问题描述
java.util.concurrent.Executor
如何创建真实线程?
假设我正在实现Executor或使用任何执行程序服务(如ThreadPoolExecutor)。 JVM内部如何工作?
How does java.util.concurrent.Executor
create the "real" thread?
Suppose I am implementing Executor or using any executor service (like ThreadPoolExecutor). How does JVM internally work?
推荐答案
它调用 ThreadFactory
。查看 Executors
类。请注意,它们都有一个重载参数,您可以在其中提供 ThreadFactory
实现。 ThreadFactory
界面基本上是
It calls ThreadFactory
. Look at the Executors
class. Note they all have an overloaded argument where you can supply a ThreadFactory
implementation. The ThreadFactory
interface is basically
public Thread newThread(Runnable runnable);
并且默认实现如果不提供基本上只是返回新线程(runnable) );
and the default implementation if not supplied basically just is return new Thread(runnable);
为什么要覆盖它 - 这对于设置线程名称和守护程序状态等非常有用。
Why override this - well it's very useful for setting the Thread name and daemon status among other things.
这篇关于java.util.concurrent.Executor如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!