What is the most efficient method to process a String Freemarker syntax in Java -
here our use case. loading freemarker syntax database , processing it. processing close million of records. things working fine. when profile application, see freemarker processing method bottleneck , taking time. having read freemarker documentation, got pointers on issue be. everytime doing processing, creating new freemarker.template.template object (creation of seems expensive). not find right/more efficient way of doing this.
public ftltemplateengine() { cfg = new configuration(); } public string process(string template, map<string, object> input) throws ioexception, templateexception { string rc = null; final writer out = new stringwriter(); try { final template temp =new template("temporarytemplate", new stringreader(template), cfg); temp.process(input, out); } catch (invalidreferenceexception e) { log.error("unable process ftl - " + template); throw new invalidreferenceexception("ftl expression has evaluated null or refers doesn't exist. - " + template, environment.getcurrentenvironment()); } catch (templateexception e) { log.error("unable process ftl - " + template); throw new templateexception("unable process ftl - " + template, e, environment.getcurrentenvironment()); } catch (ioexception e) { log.error("unable process ftl - " + template); throw new ioexception("unable process ftl - " + template); } rc = out.tostring(); out.close(); return rc.trim(); }
have process method called every time freemarker needs parsed. in method creating new template object everytime. there way avoid this?
afair don't call template
constructor directly, use configuration
instance (see get template , template loading). configuration
object employs caching, help. might need write own templateloader
in order load freemarker templates database.
Comments
Post a Comment