Take advantage of COM+ object pooling

VB6 objects can’t be pooled under COM+, because they are apartment threaded. This restriction is void with VB.NET objects (and all .NET objects in general), because they are free-threaded. To make an object poolable you just need to decorate the class with the ObjectPooling attribute:

Imports System.EnterpriseServices Public Class BankTransfer     Inherits ServicedComponents    ' ...End Class

The attribute’s constructor is overloaded to let you initialize the Enabled, MaxPoolSize, and MinPoolSize properties:

' enable object pooling, with MaxPoolSize set to 100, and MinPoolSize set to 10 

The default value for MinPoolSize is 0, the default value for MaxPoolSize is 1,048,576. You can also set the CreationTimeout property, whose default value is 60 milliseconds, which indicates the time to wait for an object to become available in the pool before throwing an exception:

' as in previous example, but set a timeout of 10 milliseconds 

Notice that all serviced components implement the IDisposable interface. A client should call Dispose as soon as the object isn’t used any longer, because the Dispose method ‘s implementation of a serviced component maps to the ServicedComponent.DisposeObject shared method, which puts the disposed object back in the pool.

Another technique for automatically put the object back to the pool when clients don’t need it any longer, and that works without having the client explicitly call the Dispose method, is applying the JustInTimeActivation attribute to make the component support JIT activation. In this case COM+ puts the object back to the pool at the end of any method call that sets the “done” bit. This can be done very easily if you mark a method with the AutoComplete attribute:

 Public Class BankTransfer     Inherits ServicedComponents         Sub Transfer(fromAccount As String, toAccount As String, _        Money As Decimal)        ' ...        ' this object is put back in the pool when this method completes    End Sub    End Class

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet

payment via phone

7 Ways Technology Has Changed Traditional Payments

In today’s digital world, technology has changed how we make payments. From contactless cards to mobile wallets, it’s now easier to pay for goods and services without carrying cash or using a checkbook. This article will look at seven of the most significant ways technology has transformed traditional payment methods.