Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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 Spring原型引用单例_Java_Multithreading_Spring_Concurrency_Prototype Scope - Fatal编程技术网

Java Spring原型引用单例

Java Spring原型引用单例,java,multithreading,spring,concurrency,prototype-scope,Java,Multithreading,Spring,Concurrency,Prototype Scope,我正在使用ConcurrentTaskExecutor同时运行多个任务。在spring中,默认情况下,它的作用域为singleton 这里我的taskExecutor是原型,threadPoolExecutor是no.t 请求时,将返回一个新的任务执行器。我的问题是,既然我们引用的是prototype中的threadPoolExecutor,那么threadPoolExecutor会是一个新实例吗 <bean id="taskExecutor" class="org.springframe

我正在使用
ConcurrentTaskExecutor
同时运行多个任务。在spring中,默认情况下,它的作用域为singleton

这里我的
taskExecutor
是原型,
threadPoolExecutor
是no.t

请求时,将返回一个新的
任务执行器
。我的问题是,既然我们引用的是prototype中的
threadPoolExecutor
,那么
threadPoolExecutor
会是一个新实例吗

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ConcurrentTaskExecutor" scope="prototype">
    <property name="concurrentExecutor" ref="threadPoolExecutor"/>
</bean>
<bean id="threadPoolExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="100" />
    <property name="maxPoolSize" value="200" />
    <property name="queueCapacity" value="1000" />
</bean>

关键词“prototype”只意味着每次向Spring请求实例时,都会得到一个新实例。用你现有的线路,你只需要问一次。因此,我希望taskExecutor bean是一个单独的实例。

prototype关键字只是意味着每次向Spring请求实例时,都会得到一个新的实例。用你现有的线路,你只需要问一次。因此,我希望taskExecutor bean是一个单独的实例。

不,prototype
关键字没有“deep”范围。它不适用于引用的bean或内部bean


对于标记为prototype的bean,即
taskExecutor
,Spring将在您每次请求时创建一个新实例。但是所有这些新的TaskExecutor都将包含相同的
threadPoolExecutor

的单例实例。否,
prototype
关键字没有“deep”范围。它不适用于引用的bean或内部bean


对于标记为prototype的bean,即
taskExecutor
,Spring将在您每次请求时创建一个新实例。但所有这些新TaskExecutor都将包含相同的
threadPoolExecutor

单例实例(假设它们位于相同的上下文中),那么threadPoolExecutor将是单例(假设它们位于相同的上下文中),那么threadPoolExecutor将是单例