Sdílet prostřednictvím


Just-in-Time Activation

The COM+ Just-in-Time (JIT) Activation service allows idle server resources to be used more productively. When a component is configured as JIT activated, COM+ can deactivate an instance of it while a client still holds an active reference to the object. The next time the client calls a method on the object, COM+ reactivates the object transparently to the client, just in time.

Note   For a component configured as JIT activated, the object is activated when first created.

On the method call return, COM+ deactivates the object but leaves the context in memory. The deactivated object releases all resources, including locks on expensive data stores.

Note   From a performance viewpoint, it is better not to implement a finalizer in a ServicedComponent derived class and instead place this logic in the DisposeObject method. Although the ServicedComponent proxy has a finalizer, it calls the finalizer on the ServicedComponent derived class by using reflection.

To enable JIT activation, apply the JustInTimeActivationAttribute attribute to a class that derives from System.EnterpriseServices.ServicedComponent. Also, to ensure the object is deactivated on the method call return, it is necessary to set the object's done bit. For transactional components, you can either apply the AutoCompleteAttribute to a class or call ContextUtil.SetComplete or ContextUtil.SetAbort. For non-transactional components, call ContextUtil.DeactivateOnReturn.

Note   Automatic transactions require JIT activation; therefore, JIT activation is implicitly enabled when classes are configured for automatic transactions.

The following example shows how to enable JIT activation and deactivation on instances of the TestObjectPooling class.

<JustInTimeActivation()> _
Public Class TestObjectPooling 
Inherits ServicedComponent
[JustInTimeActivation]
public class TestObjectPooling : ServicedComponent

See Also

Summary of Available COM+ Services | JustInTimeActivationAttribute | System.EnterpriseServices Namespace