oxygenan
oxygenan

Reputation: 1033

XStream performance query

I am trying to get the xml conversion response for an object in my code as below

XStream xstream=new XStream();

xstream.processAnnotations(

new Class[]{SomeResponseBean.class,SomeSectionResponseBean.class});
xstream.toXML(objectForConversion);

Do we need to instantiate XStream instance for every conversion or we can have it a single instance and reuse ?

Our application has huge volume requests .

Upvotes: 0

Views: 249

Answers (1)

Leo G.
Leo G.

Reputation: 458

You don't need to instantiate XStream for every conversions since the XStream object is Thread safe. The initial instantiation/configuration of XStream is time-consuming, so it is a good thing to define the instance as static in your class :

   private static final XStream XSTREAM;
   static {
        XSTREAM = new XStream();
        XSTREAM.aliasPackage(...);
        //Other configurations
    }

Upvotes: 1

Related Questions