我们使用Rythm引擎并且偶尔会出现以下错误。它在90%的时间内都能正常工作。我们为每个线程创建一个实例
INFO | jvm 1 | 2017/02/14 11:01:12 | java.lang.ClassFormatError: Incompatible magic value 3405691594 in class file C0a10f69e_cfb4_390e_ac5d_bbf66958669e__R_T_C__
INFO | jvm 1 | 2017/02/14 11:01:12 | at java.lang.ClassLoader.defineClass1(Native Method)
INFO | jvm 1 | 2017/02/14 11:01:12 | at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.internal.compiler.TemplateClassLoader.loadTemplateClass(TemplateClassLoader.java:297)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.internal.compiler.TemplateClassLoader.loadClass(TemplateClassLoader.java:254)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.internal.compiler.TemplateClass.getJavaClass(TemplateClass.java:371)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.internal.compiler.TemplateClass.templateInstance_(TemplateClass.java:387)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.internal.compiler.TemplateClass.asTemplate(TemplateClass.java:413)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.internal.compiler.TemplateClass.asTemplate(TemplateClass.java:419)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.RythmEngine.getTemplate(RythmEngine.java:924)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.RythmEngine.getTemplate(RythmEngine.java:945)
INFO | jvm 1 | 2017/02/14 11:01:12 | at org.rythmengine.RythmEngine.render(RythmEngine.java:1019)
这是我们创建引擎的方式
public class RythmEngineUtil {
/**
* clear the rythm Pre compiled data
*/
static{
try {
File dir = new File("./", "__rythm");
if(!dir.exists()){
dir.mkdir();
}else{
deleteDirAndChildren(dir);
}
}catch(Exception e){
e.printStackTrace();
}
}
private static void deleteDirAndChildren(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
new File(dir, children[i]).delete();
}
}
}
/**
* Initilize Rythm Engine
*/
private static ThreadLocal<RythmEngine> rythmEngine = new ThreadLocal<RythmEngine>() {
protected RythmEngine initialValue() {
Map<String, Object> conf = new HashMap<String, Object>();
conf.put("rythm.codegen.compact", false);
conf.put("engine.precompile_mode", true);
conf.put("engine.load_precompiled", true);
conf.put("home.template","xyz/some");
conf.put("home.precompiled.dir", new File("./", "__rythm"));
RythmEngine engine = new RythmEngine(conf);
System.out.println("Got new RythmEngine -" + engine.getId());
return engine;
}
};
public static RythmEngine getEngine() {
return rythmEngine.get();
}
private RythmEngineUtil() {
}
private static RythmEngineUtil _instance = new RythmEngineUtil();
public static RythmEngineUtil getInstance() {
return _instance;
}
}
然后像
一样使用它RythmEngineUtil.getEngine()