Just-in-Time Activation and Pooling


In enterprise applications, many server resources often sit idle waiting for client requests. The problem arises from the fact that, in most circumstances, these resources are consuming precious space on the server whether they are idle or not. The Just-in-Time Activation service provides a way around the wasting of idle resources. An object that is JIT-activated will be activated just before a method is invoked. When the call is complete, it will be deactivated again. Even while the object is deactivated, clients with references to that object will still have valid references. This can create a performance increase for components that are called infrequently.

To create a component that is JIT-activated, you need to first create a class that inherits from System.EnterpriseServices.ServicedComponent. To do this, you need to add a reference to the System.EnterpriseServices assembly. A class that is JIT-activated looks like this:

[JustInTimeActivation] public class MyJITClass : ServicedComponent {     // class implementation } 


The sequence of events for working with a JIT-activated object is as follows:

  1. Client/consumer of the component creates an instance of the object.

  2. Client invokes a method call on the component.

  3. Component is activated.

  4. Actual method is invoked.

  5. Component is de-activated.

The concept of object pooling deals with another enterprise resource issue. Components within an enterprise application often have very high instantiation overhead. Their initial use often obtains things like database connections or even remote connections to other parts of the application via web services or remoting. Situations where it takes a long time to create objects but those objects are not used for very long are perfect for pooling.

An object pool is a store of preinstantiated objects. If 50 objects are sitting in a pool waiting for a client to make a request, those clients don't incur the heavy initial creation penalty. The following class will reside in an object pool:

[JustInTimeActivation] [ObjectPooling(MinPoolSize=1, MaxPoolSize=30, CreationTimeout=1000)] public class PooledObject : ServicedComponent {     public PooledObject() { }     protected override void Activate()     {        // object is taken from pool to service a client request     }     protected override void Deactivate()     {       // object put back in pool     } } 


Object pooling is one of the powerful features of COM+ and it alleviates some of the burden and cost of the initial instantiation of objects by storing a pool of preinstantiated components and making them available for immediate use.



Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net