Object Instance Pooling

The final concern when scaling applications is object instance pooling, which allows for the creation of a group of objects that can be shared by many applications. When a pool of objects is shared, the system has to create far fewer objects than if each user had an individual copy. Therefore, resources are used more efficiently. MTS provides object instance pooling, but you must make slight changes to your business objects in order to take full advantage of MTS.

When a business object is created under MTS, a special object named ObjectContext is created to monitor the process. The ObjectContext object monitors the resource usage of a business object and notifies MTS when the object can be returned to the pool. Normally, an object is pooled only after the client releases all references to it. However, if you change your code slightly, you can actually notify MTS directly that the object is ready to return to the pool. Cycling business objects in and out of the pool in MTS is called Just-In-Time (JIT) activation and As-Soon-As-Possible (ASAP) deactivation. JIT/ASAP pooling is the most efficient way of using system resources.

Enabling JIT/ASAP pooling requires that your business object communicate directly with the ObjectContext object assigned by MTS. This is done by using a special function named GetObjectContext, which is a member of the MTS API. To access this function, you must set a reference to MTS in the References dialog box of Visual Basic. Once the reference is set, you can use the following code to access the ObjectContext object:

Dim objContext As MTxAS.ObjectContext Set objContext = GetObjectContext() 

When your business object has a reference to the ObjectContext object, it can easily call the SetComplete method to tell MTS to recycle the object. This method causes MTS to place the business object back in the pool for reuse.

When objects are recycled in this way, MTS can use just a few objects to service many clients simultaneously. Of course, recycling objects means that any data retained in the objects is lost. Therefore, do not create business objects for permanent data storage. Instead, use Session variables to save any required data in the client that calls.



Programming Active Server Pages
Programming Active Server Pages (Microsoft Programming Series)
ISBN: 1572317000
EAN: 2147483647
Year: 1996
Pages: 84

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