精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细


2019-11-09 02:02:57  阅读:23  来源: 互联网

标签:spring-boot concurrency single-page-application java

我已经复制了一个示例Spring Boot SPA.我想了解,如果多个人通过URL使用网页会发生什么. Java是否为每个调用创建Web应用程序的实例?内存资源不共享,对,也就是说,如果附加了一个列表对象,每个用户都会看到自己的列表吗?


spring-boot bean的默认范围是单例.假设您的bean不在管理状态,那么您可以使用默认行为:


4.4.1 The singleton scope

When a bean is a singleton, only one shared instance of the bean will be managed, and all requests for beans with
an id or ids matching that bean definition will result in that one
specific bean instance being returned by the Spring container.

To put it another way, when you define a bean definition and it is
scoped as a singleton, then the Spring IoC container will create
exactly one instance of the object defined by that bean definition.
This single instance will be stored in a cache of such singleton
beans, and all subsequent requests and references for that named bean
will result in the cached object being returned.


4.4.2 The prototype scope

The non-singleton, prototype scope of bean deployment results in the creation of a new bean instance every time a
request for that specific bean is made (that is, it is injected into
another bean or it is requested via a programmatic getBean() method
call on the container). As a rule of thumb, you should use the
prototype scope for all beans that are stateful, while the singleton
scope should be used for stateless beans.

来源: https://codeday.me/bug/20191109/2010933.html


Copyright (C)ICode9.com, All Rights Reserved.