我寫了一個包含mailbuilding部分的庫。這個mailbuilding部分使用了Velocity。該mailbuilder類是如下 -Java Velocity引擎初始化問題
public class mailBuilder {
public void initialize() throws Exception
{
Properties props = new Properties();
log.info("About to set the ClassPath for Velocity specific tasks");
props.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
props.setProperty("classpath." + VelocityEngine.RESOURCE_LOADER + ".class", ClasspathResourceLoader.class.getName());
try
{
log.info("Just before");
Velocity.init(props);
log.info("Just after");
}
catch (Exception e)
{
log.error("Caught Execption on velocityEngine init", e);
throw new Exception("Caught Execption on velocityEngine init", e);
}
log.info("Completed initializing Velocity Engine");
}
public String returnMailstring() throws Exception {
initialize();
....
....
}
}
現在,當我運行的結果,從Eclipse測試這個庫,它的結果如預期,事情似乎罰款。 我有一個Web應用程序接受來自UI的請求,並使用ExecutorService(newSingleThreadExecutor)在後臺無聲地逐一處理這些用戶請求。
我注意到我對上述庫的調用掛在了郵件構建部分,特別是在Velocity.init(props)
沒有拋出異常,但該線程似乎掛起在VelocityEngine初始化。 我在網上查了一下,並沒有運氣,可能是什麼問題。 任何幫助如何問題將是巨大的。
感謝 p1ng
我已經嘗試通過與VelocityEngine obects工作。我得到了相同的結果,線程掛在ve.init()。 – ping 2011-12-29 16:47:11
你可以嘗試在應用程序啓動時進行一次初始化嗎? – MahdeTo 2011-12-29 18:25:59
嘗試了單例方法並面臨同樣的問題,線程掛在Velocity.init(prop)上。我也嘗試使用ClasspathResourceLoader的FileResourceLoader無效。 我開始認爲這個問題可能與傳遞給VelocityEngine的Properties對象相關。 – ping 2011-12-30 11:32:57