Questions tagged [object-pooling]

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand.

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When the client has finished, it returns the object to the pool rather than destroying it; this can be done manually or automatically.

Object pools are primarily used for performance: in some circumstances, object pools significantly improve performance. Object pools complicate object lifetime, as objects obtained from and return to a pool are not actually created or destroyed at this time, and thus require care in implementation.

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. Object pooling requires resources – memory and possibly other resources, such as network sockets, and thus it is preferable that the number of instances in use at any one time is low, but this is not required.

http://en.wikipedia.org/wiki/Object_pool_pattern

171 questions
37
votes
9 answers

Can't find a modern Implementation of Object Pool in Java

I'm looking for a modern implementation of an object pool in Java. I can see the apache commons one, but to be honest, I'd rather one that uses generics, and the concurrency stuff from more recent versions of java. Does the commons pool really work…
time4tea
  • 2,169
  • 3
  • 16
  • 21
32
votes
8 answers

What is Object Pooling in Java?

What is object pooling and what is a weak object reference ? How can we implement them using Java?
Himanshu
  • 881
  • 2
  • 8
  • 5
21
votes
6 answers

Is there a general-purpose object pool for .NET?

I have a class that is expensive to construct, in terms of time and memory. I'd like to maintain a pool of these things and dispense them out on demand to multiple threads in the same process. Is there a general-purpose object pool that is already…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
16
votes
1 answer

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…
Cuga
  • 17,668
  • 31
  • 111
  • 166
14
votes
4 answers

Object pool vs. dynamic allocation

When should one prefer object pool over dynamically allocated objects? I need to create and destroy thousands of objects per second. Is it by itself enough to decide in favor of object pool? Thanks.
jackhab
  • 17,128
  • 37
  • 99
  • 136
12
votes
5 answers

Android view object reuse -- prevent old size from showing up when View reappears

EDIT: One more piece of possibly relevant info: The use case in which I see the problem is tab switching. That is, I create view X on tab A, remove it when leaving tab A, then recycle it into tab B. That's when the problem happens. This is also…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
11
votes
6 answers

Generic InternPool in Java?

How would I write a generic InternPool in Java? Does it need a Internable interface? String in Java has interning capabilities; I want to intern classes like BigDecimal and Account.
user400860
  • 111
  • 3
9
votes
7 answers

Does this basic Java object pool work?

Does the following basic object pool work? I have a more sophisticated one based on the same idea (i.e. maintaining both a Semaphore and a BlockingQueue). My question is - do I need both Semaphore and BlockingQueue? Am I right that I don't need…
looeeese
  • 453
  • 2
  • 5
  • 9
8
votes
3 answers

Is there an open source thread safe C++ object pool implementation?

I need to create a pool of socket connections which will be served to multiple worker threads. Is there a thread safe object pool implementation with functionality similar to Apache Commons' GenericObjectPool?
mahonya
  • 9,247
  • 7
  • 39
  • 68
8
votes
3 answers

Is there any reason for an object pool to not be treated as a singleton?

I don't necessarily mean implemented using the singleton pattern, but rather, only having and using one instance of a pool. I don't like the idea of having just one pool (or one per pooled type). However, I can't really come up with any concrete…
Chris Charabaruk
  • 4,367
  • 2
  • 30
  • 57
7
votes
3 answers

How to throttle webservice calls in a Java web application

My requirement is very simple to understand. I want to call a web service from my Java web application with restriction of maximum 10 webservice calls per minute. Just after 1 minute, I can establish another 10 connection, regardless the state of…
Badal
  • 4,078
  • 4
  • 28
  • 28
7
votes
3 answers

Generic ObjectPool - how to return a generic class?

I am trying to develop an ObjectPool, which can be used with any Object without changing the source of neither the Pool nor the Object - but I can´t find any way to write the get()-function ("Maincode" getting some Object from Pool) as there is a…
Benjamin Schwalb
  • 1,124
  • 11
  • 31
5
votes
1 answer

Proper usage of ArrayPool with a reference type

What is the proper way to use ArrayPool with reference types? I was assuming that it would be full of objects that were just 'newed up' with the default constructor. For example, in the code below, all the Foobars are null when you first rent…
lifebythedrop
  • 401
  • 3
  • 18
5
votes
1 answer

Java - performance of object pool vs new object instantiation

I'm currently trying to build some code execution optimization for a contest, and was looking at the ObjectPool pattern to favor object reuse instead of new object instantiation. I've put together a small project (and the only test class) to…
Sébastien Tromp
  • 603
  • 1
  • 15
  • 30
5
votes
1 answer

Should I reuse DatagramPacket?

I am building a UDP-based application that receives and sends multiple packets. I could build a new DatagramPacket for each send, or I recycle one instance for the life of my application. Are there any advantages to reusing a DatagramPacket?…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
1
2 3
11 12