SRaj
SRaj

Reputation: 1338

Object pool vs Object container

What is the difference between object container (such as tomcat / spring container) vs object pool? At a high level both manages the object life cycle. Only difference I note is that multiple objects are loaned from pool of the similar type while the container creates objects of different types which may be used in the application. Interested to know if there is something more to it...

Upvotes: 1

Views: 445

Answers (2)

sathya_dev
sathya_dev

Reputation: 513

Object Pool:

It is a collection of Objects from which we can get an available Object for our operational purposes.

You can think of Object pool as a deck of cards, from which you can draw a card.

Object Container:

It is a specialized environment for an object to execute. The container process the object with the pre defined life cyle methods.

You can think of Object container as Game Table, in which we're playing with the cards drawn from deck.

Upvotes: 2

Quicksilver002
Quicksilver002

Reputation: 735

The pool reduces the number of objects created. If you need an object, ask the pool for one. If it has one to give you, it does. Otherwise it creates a new one. When you're done with the object, return it to the pool for later reuse.

Upvotes: 0

Related Questions