BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Advising Domain Objects without AspectJ

Advising Domain Objects without AspectJ

In a recent article on Java.net Eric Batzdorff considers the application of AOP in respect to singletons versus domain objects. He is exploring the differences as a result of the desire to advise objects to separate concerns. Batzdorff points out that the weight of using such technologies can be much more noticeable when advising domain objects versus singletons:

1000000 iteration test for 'Create dynamic proxy using Proxy.newProxyInstance()'
WARMED UP in 16 ms
Iterations ,Total Time(ms) ,Avg(ms)/Iteration ,Transactions/sec
1000000 ,7978 ,0.007978 ,125344.71

1000000 iteration test for 'Create regular object using new'
WARMED UP in 0 ms
Iterations ,Total Time(ms) ,Avg(ms)/Iteration ,Transactions/sec
1000000 ,63 ,0.000063 ,15873015

After pointing out the drastic timing differences between a simple new object instanciation versus a dynamic proxy, he continues by exploring a few options to optimize the advising of domain objects which may have many instances being created. These alternatives are considered in comparison to AspectJ due to the learning curve and effort needed to integrate it into development environments.

First considered is using an object pool but as Batzdorff points out this creates a new set of concerns that must be addressed:

  • Returning the advised objects back to the pool when clients are done using them.
  • Clearing the state within an object before it is used again by another client.
  • Hoping that clients do not keep references to any objects that were released back to the pool. If clients do not cooperate, this could cause all sorts of hard-to-track-down data integrity issues.
  • Tuning the maximum size of the pool appropriately. The size would need to be based on the hardware, amount of memory allocated to the JVM, etc.

He also looks at the pros and cons of alternative stategies such as simple Java class extension, static decorating proxies, and dynamic decorating proxies.

 

Rate this Article

Adoption
Style

BT