关于freemarker创建模板的问题.熟悉的朋友帮忙看看,谢谢

之前没接触过freemark.应项目要求使用freemark.结果发现使用freemark与不使用性能差距很大.如下是我的代码:
[code="java"]
Configuration cfg = new Configuration();
StringTemplateLoader templateLoader = new StringTemplateLoader();
templateLoader.putTemplate(
"tempTemplate",
"${fm.encode(\"${fm.encodeStr}&init=${fm.init}\")}");
cfg.setTemplateLoader(templateLoader);
cfg.setEncoding(Locale.CHINA, "UTF-8");
EncoderExample fm = new EncoderExample("test.test2");
Map map = new HashMap();
map.put("fm", fm);
CharArrayWriter writer = new CharArrayWriter(1000);
try
{
Template template = cfg.getTemplate("tempTemplate");
template.process(map, writer);
}
catch (Exception e)
{
System.out.println("Proccess ERROR." + e.getMessage());
}
finally
{
writer.flush();
writer.close();
}
[/code]

执行后发现Configuration这个类实例化的时候花费时间很长.大概200ms左右.相当于实例化普通类60000个.
请问下是否有其他创建模板的办法?或者有其他方式可以实现同样的功能?

麻烦知道的朋友帮忙下 谢谢啊~~

[quote]
多谢你的回答.不过看了他的构造方法.貌似也不是单例的啊.
Java代码 收藏代码

public Configuration() {  
      cache = new TemplateCache();  
      cache.setConfiguration(this);  
      cache.setDelay(5000);  
      loadBuiltInSharedVariables();  
  }  

但是循环创建一个对象跟创建100个对象花费的时间却差不多.不解啊~~~ [/quote]
晕啊……都有构造了当然就不是单例了,我这里说的所谓“单例”,指的是要你自己在程序里维护一个全局唯一的Configuration对象,而不是说他自己是单例的……

至于这个创建时间的问题,这个不就是java本身的特性么?第一次加载需要从jar包里加载到内存,涉及到IO,所以当然慢了,之后都是内存内操作,消耗就少得多……

Configuration这个类原则上是应当是单例的,也就是全局唯一的,所以耗时长点没啥呀?
使用时用不同的template就行了。