2018-04-02 15:59
这是异常:
java.lang.NullPointerException
at java.lang.String.(String.java:515)
at com.jfinal.template.stat.ast.Text.getChars(Text.java:91)
at com.jfinal.template.io.CharWriter.write(CharWriter.java:85)
at com.jfinal.template.stat.ast.Text.exec(Text.java:49)
at com.jfinal.template.stat.ast.StatList.exec(StatList.java:68)
at com.jfinal.template.Template.render(Template.java:79)
at com.jfinal.template.Template.renderToString(Template.java:99)
at demo.com.software.lc.JfinalSqlTest$1.run(JfinalSqlTest.java:41)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
下面是模拟多线程解析sql模板
public class JfinalSqlTest {
private static Template template;
private static String sql;
static{
Engine engine = Engine.use();
// engine.addSharedMethod(new StringUtils());
engine.addSharedMethod(new EngineUtil());
engine.setBaseTemplatePath("E:\\workspace\\demo\\src\\main\\resources\\sql");
template = engine.getTemplate("test.sql");
}
public static void main(String[] args) {
final CountDownLatch count = new CountDownLatch(10000);
try {
ExecutorService threadPool = Executors.newFixedThreadPool(100);
for (int i = 0; i < 10000; i++) {
threadPool.execute(new Runnable() {
@Override
public void run() {
try {
Map map = new HashMap();
map.put("order_pay_type","01");
map.put("channel_id",",WKLC,");
map.put("start_time","2017-12-29 17:58:03");
sql = template.renderToString(map);
// SqlPara sqlPara = SqlUtil.INSTANCE.getSqlPara(sql, map);
// System.out.println("正常解析");
} catch (Exception e) {
e.printStackTrace();
} finally{
count.countDown();
}
}
});
}
threadPool.shutdown();
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(count.await(120, TimeUnit.MINUTES)){
System.out.println("处理完成!");
};
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}