我正在尝试编写代码以使用 FTL 生成 JVM 线程转储,但在遍历 TreeMap 时遇到问题。
这是我的动作类的片段:
- - -开始 - - -
public AppsnapAction() {
traces = new TreeMap<Thread, StackTraceElement[]>(COMP);
traces.putAll(Thread.getAllStackTraces());
}
有问题的方法。
public Map<Thread, StackTraceElement[]> getAppTraces() {
// log.debug("HelloMe..in getAppTraces"+ traces);
return traces;
}
- - 结尾 - - - -
这是 FTL 的片段:
- - -开始 - - -
<h1>My Trace</h1>
<#list appTraces?keys as trace>
<h4><a name="${trace_index}">${trace}</a></h4>
<pre>
<#list appTraces[trace] as traceline>
at ${traceline}
</#list>
</pre>
</#list>
- - - 结尾 - - - -
代码在这一行中断:“<#list appTraces[trace] as traceline>”
除了以下例外:
2013-09-15 22:58:35,701 [http-8080-1] 错误 freemarker.runtime -
get(Thread[ContainerBackgroundProcessor[StandardEngine[Catalina]],5,main]) 在 java.util.TreeMap 实例上失败 有问题的指令:
==> 将 appTraces[trace] 列为跟踪线 [在 /resources/templates/td-Page.ftl 中的第 42 行第 5 列]
程序员的 Java 回溯:
freemarker.template.TemplateModelException: get(Thread[ContainerBackgroundProcessor[StandardEngine[Catalina]],5,main]) failed on instance of java.util.TreeMap
at freemarker.ext.beans.BeanModel.get(BeanModel.java:223)
at freemarker.core.DynamicKeyName.dealWithStringKey(DynamicKeyName.java:136)
at freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:94)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:213)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Thread
at com.jivesoftware.helloworld.action.AppsnapAction$1.compare(AppsnapAction.java:1)
at java.util.TreeMap.getEntryUsingComparator(TreeMap.java:351)
at java.util.TreeMap.getEntry(TreeMap.java:322)
at java.util.TreeMap.get(TreeMap.java:255)
at freemarker.ext.beans.MapModel.invokeGenericGet(MapModel.java:127)
at freemarker.ext.beans.BeanModel.get(BeanModel.java:185)
... 202 more
请对如何遍历内部循环有任何想法吗?