Hessian Performance OutputStream

From Resin 4.0 Wiki

Jump to: navigation, search

Cookbook-48.pngEmail-48.png

To speed up Hessian writing, you should use a HessianFactory and you may also set the 'unshared' property.

Since HessianFactory caches the introspection of your objects, each new object can skip the overhead of the reflection. And, since Hessian2Output objects can be reused, you can save the garbage-collection time.

The 'unshared' property can speed Hessian when your object graphs do not share sub-objects and are not circular. For specifically designed message, this is generally true.

import com.caucho.hessian.io.*;

private HessianFactory _hFactory = new HessianFactory();
...
 
Hessian2Output hOut = hFactory.createHessian2Output(null);

for ( ... ) {
  OutputStream myOs = ...
  hOut.init(myOs);
  hOut.setUnshared(true);

  hOut.writeObject(myObj);
  hOut.close();
}

The setUnshared tells Hessian that none of the objects will be shared, which will save some HashMap lookups. Using the HessianFactory also saves time by saving the reflection information and also the Hessian2Output objects.

The Input processing performance can also be performed in the same say

Hessian2Input hIn = hFactory.createHessian2Input(null);

for (...) {
  InputStream myIs = ...
  hIn.init(myIs);
 
  Object myObj = hIn.readObject();
  hIn.close();
}
Personal tools
TOOLBOX
LANGUAGES