Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one manage object pooling in Spring?

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.

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?

like image 912
Cuga Avatar asked May 21 '09 13:05

Cuga


People also ask

What is object pooling in Java with example?

An object pool is a collection of a particular object that an application will create and keep on hand for those situations where creating each instance is expensive. A good example would be a database connection or a worker thread. The pool checks instances in and out for users like books out of a library.

Why do we need object pooling?

Benefits. Object pooling can offer a significant performance boost in situations where the cost of initializing a class instance is high and the rate of instantiation and destruction of a class is high – in this case objects can frequently be reused, and each reuse saves a significant amount of time.

What is object pooling in Ado net?

ObjectPool is part of the ASP.NET Core infrastructure that supports keeping a group of objects in memory for reuse rather than allowing the objects to be garbage collected. You might want to use the object pool if the objects that are being managed are: Expensive to allocate/initialize.

What is pooling in Java?

Connection pooling is a technique of creating and managing a pool of connections that are ready for use by any thread that needs them. Connection pooling can greatly increase the performance of your Java application, while reducing overall resource usage.


1 Answers

Pooling can be applied to any POJO with spring.

See here for more information.

like image 179
toolkit Avatar answered Oct 19 '22 05:10

toolkit