Sunday, July 22, 2007

Object Pooling

ObjectPooling:
• Avoid the overhead of creating objects from scratch
• When an object is activated, it is pulled from the pool, on deactivation, it is placed back
• Pooling can be configured by applying the ObjectPoolingAttribute to a class
• ObjectPoolingAttribute derives from System.EnterpriseServices.ServicedComponent class
• Object pooling allows controlling the number of connections used
• Object pooling enforces minimums and maximums, precaution needed when defining maximum

Code Listing: ObjectPooling

[ObjectPooling(Enabled=true; MinPoolSize=2; MaxPoolSize=5; CreationTimeout=20000)]
public class TestObjectPooling : ServicedComponent
{

public void Perform() {}
protected override void activate() {}
protected override void Deactivate() {}

protected override bool CanBePooled()
{
return true;
}

}

No comments: