3

运行一段时间后,我的应用程序陷入僵局。我进行了线程转储,并注意到我所有留下的应用程序线程都停留在以下状态

"APP-Thread-20" prio=6 tid=0x0000000007414800 nid=0x1268 waiting on condition [0x000000000951f000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.$$YJP$$park(Native Method)
    - parking to wait for  <0x00000000e0179568> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at sun.misc.Unsafe.park(Unsafe.java)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1987)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:662)

   Locked ownable synchronizers:
    - None

唯一处于可运行状态的线程卡在使用 SAX Parser 的代码上。下面给出了线程转储

"APP-Thread-19" prio=6 tid=0x0000000007413800 nid=0x18b4 runnable [0x00000000094de000]
   java.lang.Thread.State: RUNNABLE
    at java.net.SocketInputStream.$$YJP$$socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead0(SocketInputStream.java)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    - locked <0x00000000e2f3fee8> (a java.io.BufferedInputStream)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:697)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:640)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)
    - locked <0x00000000e2f3ff90> (a sun.net.www.protocol.http.HttpURLConnection)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    at org.apache.xerces.impl.XMLDTDScannerImpl.startPE(Unknown Source)
    at org.apache.xerces.impl.XMLDTDScannerImpl.skipSeparator(Unknown Source)
    at org.apache.xerces.impl.XMLDTDScannerImpl.scanDecls(Unknown Source)
    at org.apache.xerces.impl.XMLDTDScannerImpl.scanDTDExternalSubset(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
    at com.test.Parser.Parser.parseDocument(Parser.java:33)
    at com.test.processor.LinkExtractor.extractLinksFromXml(LinkExtractor.java:222)
    at com.test.processor.LinkExtractor.process(LinkExtractor.java:102)
    at com.test.content.pipeline.PipelineProcessingTask.run(PipelineProcessingTask.java:76)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

   Locked ownable synchronizers:
    - <0x00000000e017c3b8> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)

所有线程都在处理一系列任务,其中解析只是其中一项任务。解析代码不同步,每个线程都在执行新的 Parser().parse()。

这个问题是否以 SAXParser 为中心?还是我看错了方向?

我有 3 个线程转储,并且在所有 3 个场景中都是相同的。

这是解析的代码。请求是一个httpMethod。

byte[] data = IOUtils.toByteArray(req.getResponseBodyAsStream());
body = new String(data,"UTF-8").trim();
Parser parser = new Parser();
List<String> entries = parser.parseDocument(response);
4

2 回答 2

3

您的解析器正在等待来自网络的输入,同时它正在阻塞所有其他线程。

于 2013-03-07T07:22:15.137 回答
1

因此,您的应用程序中没有死锁。

队列中没有任务。因此,除了一个之外的所有工作人员都在等待一些任务进入队列。

一名执行工作人员加载 XML 源以通过 SAX 进行解析。看起来它是缓慢的操作。可能 XML 可能很大或网络速度很慢。

环境问题。由于某些原因,没有人将任务放入队列中。还要检查通过网络加载 XML 的性能。

于 2013-03-07T10:15:10.960 回答