java 如何在 Spring 中管理对象池?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/893041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:15:26  来源:igfitidea点击:

How does one manage object pooling in Spring?

javaspringspring-mvcaopobject-pooling

提问by Cuga

It's my understanding that in Spring, all objects are treated by default as singletons. If singleton is set to false, then a new object will be served at each request.

我的理解是,在 Spring 中,默认情况下所有对象都被视为单例。如果 singleton 设置为 false,则每个请求都会提供一个新对象。

But what if I wanted to pool objects? Say set a range from a min of 1 to a max of 10 instances? Is this possible using Spring?

但是如果我想池化对象呢?假设设置从最小 1 到最大 10 个实例的范围?这可以使用 Spring 吗?

回答by toolkit

Pooling can be applied to any POJO with spring.

池化可以应用于任何带有弹簧的 POJO。

See herefor more information.

请参阅此处了解更多信息。