How can I improve JAXB performance? -


here conversion code. taking long time when dealing large data... calling method million times... see holding threads while.

please suggest me ways improve performance!

public class genericobjectxmlconverter<t> {    private t t = null;   private static jaxbcontext jaxbcontext =null;   public genericobjectxmlconverter() {    }   public genericobjectxmlconverter(t obj){     t = obj;   }    protected final logger  log = logger.getlogger(getclass());    /**    * converts java object , xml string message type.    * @param object object convert    * @return string converted xml message string    */   public string objecttoxmlmessage(t object) {     stringwriter stringwriter = new stringwriter();     //jaxbcontext jaxbcontext=null;     try {       jaxbcontext = jaxbcontext.newinstance(object.getclass());       marshaller jaxbmarshaller = jaxbcontext.createmarshaller();       jaxbmarshaller.marshal(object, stringwriter);     } catch (jaxbexception e) {       log.warn("jaxbexception occured while converting java object xml string :"+e.getmessage());     }        /*if(log.isdebugenabled())          log.debug("xml string after conversion:"+stringwriter.tostring());*/        return stringwriter.tostring();   }    /**    * converts xml string message java object    * @param string string message convert    * @return object result java object. if message parameter null      *  method return null.    */   @suppresswarnings("unchecked")   public t xmltoobject(string message) {     if(message.equals("") || message.equals(" ") || message.length()==0){       return null;     }else{       t object=null;       try {         jaxbcontext = jaxbcontext.newinstance(t.getclass());         stringreader reader = new stringreader(message);         unmarshaller jaxbunmarshaller = jaxbcontext.createunmarshaller();         object = (t)jaxbunmarshaller.unmarshal(reader);         } catch (jaxbexception e) {         log.warn("jaxbexception occured while converting xml string java object :"+e.getmessage());         }        /* if(log.isdebugenabled()){           log.debug("java object after conversion:"+object.tostring());         }*/       return object;     }   }  } 

performance , jaxb runtime classes

  • you should avoid creating same jaxbcontext on , over. jaxbcontext thread safe , should reused improve performance.
  • marshaller/unmarshaller not thread safe, quick create. it's not big deal reuse them.

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -