Take advantage of COM+ object pooling

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several