Object pool pattern: Difference between revisions

Content deleted Content added
6 seconds = 6000 milliseconds, not 60000
No edit summary
Line 13:
In some object pools the resources are limited so a maximum number of objects is specified. If this number is reached and a new item is requested, an exception may be thrown, or the thread will be blocked until an object is released back into the pool.
 
The object pool design pattern is used in several places in the standard classes of the .NET frameworkFramework. One example is the .NET Framework Data Provider for SQL Server. As SQL Server database connections can be slow to create, a pool of connections is maintained. When you close a connection it does not actually relinquish the link to SQL Server. Instead, the connection is held in a pool from which it can be retrieved when requesting a new connection. This substantially increases the speed of making connections.
 
== 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. 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.
 
Line 172:
public void setTemp3(String temp3) {
this.temp3 = temp3;
}}
}
 
</syntaxhighlight><syntaxhighlight lang="java">
Line 183 ⟶ 179:
public static HashMap<PooledObject, Long> available = new HashMap<PooledObject, Long>();
public static HashMap<PooledObject, Long> inUse = new HashMap<PooledObject, Long>();
public synchronized static PooledObject getObject() {
Line 263 ⟶ 258:
{{refend}}
 
== External links ==
* [http://www.oodesign.com/object-pool-pattern.html OODesign article]
* [http://msdn2.microsoft.com/en-us/library/ms682822.aspx Improving Performance with Object Pooling (Microsoft Developer Network )]