com.sun.xml.internal.stream.XMLInputFactoryImpl#createXMLStreamReader(java.io.Reader)线程安全吗?

时间:2019-02-20 02:45:39

标签: java xml stax

我发现<%@ 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方法中是否存在资源泄漏?

0 个答案:

没有答案