Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Take advantage of COM+ object pooling

Total Hit ( 2662)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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:

Click here to copy the following block
Imports System.EnterpriseServices

<ObjectPooling()> 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

Click here to copy the following block
<ObjectPooling(True, 100, 10, CreationTimeout:=10)>

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:

Click here to copy the following block
<JustInTimeActivation(True), ObjectPooling(True)> Public Class BankTransfer
  Inherits ServicedComponents
  
  <AutoComplete()> 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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.