我发现<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%
response.setStatus(200);
%><%@include file="./dashboard/index.html"%>
方法的表现很差,所以我使用了另一种书写方式。
我这样使用Stax。
XMLInputFactory.newInstance()
XMLInputFactory仅实例一次。
public enum XMLInputFactoryBuilder {
;
private static final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
public static XMLInputFactory build() {
if (inputFactory == null) {
return XMLInputFactory.newInstance();
}
return inputFactory;
}
}
public class XMLParse {
private static final XMLInputFactory inputFactory = XMLInputFactoryBuilder.build();
public static String format(String xml) {
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(xml));
.......
}
}
方法线程安全吗?
format
方法中是否存在资源泄漏?