Other Aspects of Transactions


Several other topics relate to transactions, such as Just-In-Time activation and object pooling.

Just-In-Time

Creating and deleting components takes time. Instead of discarding the component when finished with it, why not keep it around in case another instance is required? The mechanism by which this is done is called Just-In-Time (JIT) activation, and it’s set by default for all automatic transactional components (it’s unset by default for all other COM+ components, however). This is another reason why holding state is undesirable within components - it limits the ability to share components.

All good transactional components are entirely stateless, but real life dictates differently. For example, you might want to maintain a link to your database, one that would be expensive to set up every time. The JIT mechanism provides a couple of methods that you can override in the ServicedComponent class in this case.

The method that is invoked when a JIT component is activated is called Activate, and the component that is invoked when it is deactivated is called, unsurprisingly, Deactivate. In Activate and Deactivate you put the things that you would normally put in your constructor and deconstructor. JIT can also be activated by adding the JustInTimeActivation attribute to any class within ServicedComponent.

Object Pooling

You can, if you want, take this a stage further and maintain a pool of objects already constructed and prepared to be activated whenever required. When the object is no longer required (that is, it’s deactivated), it is returned to the pool until the next time it is required. By retaining objects, you don’t have to continually create them anew, which in turn reduces the performance costs of your application. You can use the ObjectPooling attribute within your class to determine how the pool is to operate:

  <Transaction(TransactionOption.RequiresNew), _ ObjectPooling(MinPoolSize:=5, MaxPoolSize:=20, _                         CreationTimeOut:=30)> _ Public Class BankTransactions 




Professional VB 2005 with. NET 3. 0
Professional VB 2005 with .NET 3.0 (Programmer to Programmer)
ISBN: 0470124709
EAN: 2147483647
Year: 2004
Pages: 267

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