1

私のサーバーは XFire を使用して Web サービス要求を処理しています

しかし、その CPU は 100% または時には 1000% まで使用されていました

サーバーを再起動し、いくつかのリクエストの後、この奇妙な問題が再び現れました

スレッド ダンプをスキャンすると、CPU を占有するスレッドは次のようになります。

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 のバグであり、JDK6 の代わりに JDK5 を使用している可能性があることを示唆しています。

誰もそのような問題に遭遇しましたか? この問題の原因とその修正方法を教えてください。

ありがとう。

4

1 に答える 1

0

最後に、この問題を修正しました。

このトピックで述べたように、この問題の原因は JDK6 XMLStreamReader 実装のバグです。

修正方法は?

XFire のソース コードを読みました。答えは次のコードにあります。

XMLStreamReader reader = 
            STAXUtils.createXMLStreamReader(request.getInputStream(), 
                                            charEncoding,
                                            context);

STAXUtils.createXMLStreamReader は、XMLInputFactory を作成して XMLStreamReader を生成します。

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 にバグがない XMLInputFactory を生成できますが、このプロパティの設定方法がわかりません。

私のプロジェクトでは、xmlInputFactory は JDK のデフォルトの xmlInputFactory です。

 /**
* 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 システム プロパティを使用して、wstx lib などの別の XMLInputFactroy を使用できます。

于 2014-05-02T05:29:59.847 に答える