Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Executors.newScheduledThreadPool(n)创建线程意味着什么?_Java_Multithreading - Fatal编程技术网

Java 使用Executors.newScheduledThreadPool(n)创建线程意味着什么?

Java 使用Executors.newScheduledThreadPool(n)创建线程意味着什么?,java,multithreading,Java,Multithreading,创建ExecutorService时,我使用其中一个工厂创建线程,例如,我们有3个线程: Executors.newScheduledThreadPool (3) 当我们使用工厂时,资源和内存会发生什么变化?这些线程已经存在,还是在我启动任务时创建的?创建线程(本机代码)意味着什么?它将创建并返回具有以下特征的 This class specializes ThreadPoolExecutor implementation by 1. Using a custom task type,

创建ExecutorService时,我使用其中一个工厂创建线程,例如,我们有3个线程:

Executors.newScheduledThreadPool (3) 

当我们使用工厂时,资源和内存会发生什么变化?这些线程已经存在,还是在我启动任务时创建的?创建线程(本机代码)意味着什么?它将创建并返回具有以下特征的

This class specializes ThreadPoolExecutor implementation by

 1. Using a custom task type, ScheduledFutureTask for
    tasks, even those that don't require scheduling (i.e.,
    those submitted using ExecutorService execute, not
    ScheduledExecutorService methods) which are treated as
    delayed tasks with a delay of zero.

 2. Using a custom queue (DelayedWorkQueue) based on an
    unbounded DelayQueue. The lack of capacity constraint and
    the fact that corePoolSize and maximumPoolSize are
    effectively identical simplifies some execution mechanics
    (see delayedExecute) compared to ThreadPoolExecutor
    version.

    The DelayedWorkQueue class is defined below for the sake of
    ensuring that all elements are instances of
    RunnableScheduledFuture.  Since DelayQueue otherwise
    requires type be Delayed, but not necessarily Runnable, and
    the workQueue requires the opposite, we need to explicitly
    define a class that requires both to ensure that users don't
    add objects that aren't RunnableScheduledFutures via
    getQueue().add() etc.

 3. Supporting optional run-after-shutdown parameters, which
    leads to overrides of shutdown methods to remove and cancel
    tasks that should NOT be run after shutdown, as well as
    different recheck logic when task (re)submission overlaps
    with a shutdown.

 4. Task decoration methods to allow interception and
    instrumentation, which are needed because subclasses cannot
    otherwise override submit methods to get this effect. These
    don't have any impact on pool control logic though.
谢谢你的提问

These threads already exist or they create when I start the tasks?

将为
corePoolSize
大小创建和池化线程,在本例中为3。

它将创建并返回具有以下特征的

This class specializes ThreadPoolExecutor implementation by

 1. Using a custom task type, ScheduledFutureTask for
    tasks, even those that don't require scheduling (i.e.,
    those submitted using ExecutorService execute, not
    ScheduledExecutorService methods) which are treated as
    delayed tasks with a delay of zero.

 2. Using a custom queue (DelayedWorkQueue) based on an
    unbounded DelayQueue. The lack of capacity constraint and
    the fact that corePoolSize and maximumPoolSize are
    effectively identical simplifies some execution mechanics
    (see delayedExecute) compared to ThreadPoolExecutor
    version.

    The DelayedWorkQueue class is defined below for the sake of
    ensuring that all elements are instances of
    RunnableScheduledFuture.  Since DelayQueue otherwise
    requires type be Delayed, but not necessarily Runnable, and
    the workQueue requires the opposite, we need to explicitly
    define a class that requires both to ensure that users don't
    add objects that aren't RunnableScheduledFutures via
    getQueue().add() etc.

 3. Supporting optional run-after-shutdown parameters, which
    leads to overrides of shutdown methods to remove and cancel
    tasks that should NOT be run after shutdown, as well as
    different recheck logic when task (re)submission overlaps
    with a shutdown.

 4. Task decoration methods to allow interception and
    instrumentation, which are needed because subclasses cannot
    otherwise override submit methods to get this effect. These
    don't have any impact on pool control logic though.
谢谢你的提问

These threads already exist or they create when I start the tasks?

将为
corePoolSize
的大小创建和池线程,在本例中为3。

这里的“流”是什么意思?@NicolasFilotto他的意思是“线程”。是的,我指的是线程!好的,我删除了
标记,因为它根本不相关。为什么不在你不理解某些东西时阅读?这里的“流”是什么意思?@NicolasFilotto他指的是“线程”。是的,我指的是线程!好的,我删除了
标记,因为它根本不相关。为什么不在您不理解某些内容时读取?这意味着,只要我不使用这些线程,CPU时间将不会被占用?线程的基础是什么,一个无限循环?谢谢你的链接和回答!阅读ThreadPoolExecutor的文档这意味着只要我不使用这些线程,CPU时间就不会被占用?线程的基础是什么,一个无限循环?谢谢你的链接和回答!阅读ThreadPoolExecutor的文档