Hessian Performance OutputStream

From Resin 4.0 Wiki

(Difference between revisions)
Jump to: navigation, search
 
Line 14: Line 14:
 
  ...
 
  ...
 
    
 
    
  Hessian2Output hOut = hFactory.createHessian2Output();
+
  Hessian2Output hOut = hFactory.createHessian2Output(null);
 
   
 
   
 
  for ( ... ) {
 
  for ( ... ) {
Line 29: Line 29:
 
The Input processing performance can also be performed in the same say
 
The Input processing performance can also be performed in the same say
  
  Hessian2Input hIn = hFactory.createHessian2Input();
+
  Hessian2Input hIn = hFactory.createHessian2Input(null);
 
   
 
   
 
  for (...) {
 
  for (...) {
    InputStream myIs = ...
+
  InputStream myIs = ...
    hIn.init(myIs);
+
  hIn.init(myIs);
 
    
 
    
 
   Object myObj = hIn.readObject();
 
   Object myObj = hIn.readObject();
 
   hIn.close();
 
   hIn.close();
 
  }
 
  }

Latest revision as of 00:00, 4 January 2012

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