首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在XFire中解析XML会导致CPU较高?

在XFire中解析XML会导致CPU较高?
EN

Stack Overflow用户
提问于 2014-03-26 08:34:38
回答 1查看 721关注 0票数 1

我的服务器正在使用XFire处理web服务请求。

但是它的CPU占了100%,有时甚至1000%。

当我重新启动服务器时,经过一些请求,这个奇怪的问题再次出现。

我扫描线程转储,占用CPU的线程如下所示:

代码语言:javascript
复制
httpWorkerThread-18028-39" daemon prio=10 tid=0xa0832800 nid=0x1d89 runnable [0x99e69000]
java.lang.Thread.State: RUNNABLE
at com.sun.xml.stream.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:892)
at com.sun.xml.stream.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:362)
at com.sun.xml.stream.XMLReaderImpl.next(XMLReaderImpl.java:568)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:44)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)
at org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
at org.codehaus.xfire.transport.http.XFireServletController.invoke(XFireServletController.java:304)
at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:129)
at org.codehaus.xfire.transport.http.XFireServlet.doPost(XFireServlet.java:116)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:753)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:846)

似乎XFire正在解析一个XML文件,但是随着时间的推移,线程转储没有什么不同,线程就像一个无限循环中的线程。

然而,我没有足够的XFire经验,我不知道是什么原因造成的问题

我搜索了很多主题,发现它的现象和我的一样

然而,本主题暗示它可能是一个JVM错误,并且使用JDK5而不是JDK5 6。我正在尝试使用JDK5来查看它是否有帮助

有人遇到这样的问题吗?是什么原因造成了这个问题,如何解决?

经常这样。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-02 05:29:59

最后,我解决了这个问题。

造成此问题的原因是JDK6 XMLStreamReader实现的错误,正如主题所说的。

怎么修呢?

我阅读了XFire的源代码,答案是在下面的代码中:

代码语言:javascript
复制
XMLStreamReader reader = 
            STAXUtils.createXMLStreamReader(request.getInputStream(), 
                                            charEncoding,
                                            context);

STAXUtils.createXMLStreamReader将创建XMLInputFactory以生成XMLStreamReader。

代码语言:javascript
复制
public static XMLInputFactory getXMLInputFactory(MessageContext ctx)
{
    if (ctx == null) return xmlInputFactory;

    Object inFactoryObj = ctx.getContextualProperty(XFire.STAX_INPUT_FACTORY);

    if (inFactoryObj instanceof XMLInputFactory)
    {
        return (XMLInputFactory) inFactoryObj; 
    }
    else if (inFactoryObj instanceof String)
    {
        String inFactory = (String) inFactoryObj;
        XMLInputFactory xif = (XMLInputFactory) factories.get(inFactory);
        if (xif == null)
        {
            xif = (XMLInputFactory) createFactory(inFactory, ctx);
            configureFactory(xif,ctx);
            factories.put(inFactory, xif);
        }
        return xif;
    }

    if(!inFactoryConfigured){
        configureFactory(xmlInputFactory,ctx);
        inFactoryConfigured=true;
    }



    return xmlInputFactory;
}

在这段代码中,您可以配置"xfire.stax.input.factory“XFire属性来生成XMLStreamReader没有bug的XMLInputFactory,但是,我不知道如何设置这个属性。

在我的项目中,xmlInputFactory是默认的xmlInputFactory,它是JDK的。

代码语言:javascript
复制
 /**
* Create a new instance of the factory.
* This static method creates a new factory instance. 
* This method uses the following ordered lookup procedure to determine 
* the XMLInputFactory implementation class to load: 
* Use the javax.xml.stream.XMLInputFactory system property. 
* Use the properties file "lib/stax.properties" in the JRE directory. 
* This configuration file is in standard java.util.Properties format and contains 
* the fully qualified name of the implementation class with the key being the system property defined above. 
* Use the Services API (as detailed in the JAR specification), if available, to determine the classname. 
* The Services API will look for a classname in the file META-INF/services/javax.xml.stream.XMLInputFactory 
* in jars available to the runtime. 
* Platform default XMLInputFactory instance. 
* Once an application has obtained a reference to a XMLInputFactory 
* it can use the factory to configure and obtain stream instances. 
*
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
*/
public static XMLInputFactory newInstance()
  throws FactoryConfigurationError
{
    return (XMLInputFactory) FactoryFinder.find(
  "javax.xml.stream.XMLInputFactory",
  "com.sun.xml.internal.stream.XMLInputFactoryImpl");
}

因此,您可以使用javax.xml.stream.XMLInputFactory system属性来使用另一个XMLInputFactroy,例如wstx。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22655331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档