Hessian Performance OutputStream
From Resin 4.0 Wiki
(Created page with "{{Cookbook}} {{Hessian}} To speed up Hessian writing, you should use a HessianFactory and you may also set the 'unshared' property. Since HessianFactory caches the introspec...") |
|||
Line 9: | Line 9: | ||
designed message, this is generally true. | designed message, this is generally true. | ||
+ | import com.caucho.hessian.io.*; | ||
+ | |||
private HessianFactory _hFactory = new HessianFactory(); | private HessianFactory _hFactory = new HessianFactory(); | ||
... | ... | ||
− | Hessian2Output hOut = hFactory.createHessian2Output(); | + | Hessian2Output hOut = hFactory.createHessian2Output(null); |
for ( ... ) { | for ( ... ) { | ||
Line 27: | 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 = ... | |
− | + | hIn.init(myIs); | |
Object myObj = hIn.readObject(); | Object myObj = hIn.readObject(); | ||
hIn.close(); | hIn.close(); | ||
} | } |
Latest revision as of 00:00, 4 January 2012
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(); }