【发布时间】:2014-12-03 12:31:25
【问题描述】:
我正在查看我们在应用程序中遇到的一些问题。 Spring 集成用于轮询特定目录,然后处理该目录中的文件。它可以处理 5k 1kb 文件,有时会出现巨大的停顿,应用程序什么都不做,只是闲置,然后在 4 分钟内完成该过程。然后下一次运行将需要更长的时间,之后的运行时间会稍长一些,依此类推,直到我重新启动应用程序,它又回到了 4 分钟标记。有没有人遇到过这个问题。
我写了一个没有 Spring Integration 的独立版本,但没有遇到同样的问题。 我还在下面粘贴了 xml 配置,以防我做错了我无法发现的事情。
提前致谢。
<!-- Poll the input file directory for new files. If found, send a Java File object on inputFileChannel -->
<file:inbound-channel-adapter directory="file:${filepath}"
channel="inputFileChannel" filename-regex=".+-OK.xml">
<si:poller fixed-rate="5000" max-messages-per-poll="1" />
</file:inbound-channel-adapter>
<si:channel id="inputFileChannel" />
<!-- Call processFile() and start parsing the XML inside the File -->
<si:service-activator input-channel="inputFileChannel"
method="splitFile" ref="splitFileService">
</si:service-activator>
<!-- Poll the input file directory for new files. If found, send a Java File object on inputFileChannel -->
<file:inbound-channel-adapter directory="file:${direcotrypath}" channel="inputFileRecordChannel" filename-regex=".+-OK.xml">
<si:poller fixed-rate="5000" max-messages-per-poll="250" task-executor="executor" />
</file:inbound-channel-adapter>
<task:executor id="executor" pool-size="8"
queue-capacity="0"
rejection-policy="DISCARD"/>
<si:channel id="inputFileRecordChannel" />
<!-- Call processFile() and start parsing the XML inside the File -->
<si:service-activator input-channel="inputFileRecordChannel"
method="processFile" ref="processedFileService">
</si:service-activator>
<si:channel id="wsRequestsChannel"/>
<!-- Sends messages from wsRequestsChannel to the httpSender, and returns the responses on
wsResponsesChannel. This is used once for each record found in the input file. -->
<int-ws:outbound-gateway uri="#{'http://localhost:'+interfaceService.getWebServiceInternalInterface().getIpPort()+'/ws'}"
message-sender="httpSender"
request-channel="wsRequestsChannel" reply-channel="wsResponsesChannel" mapped-request-headers="soap-header"/>
<!-- Handles the responses from the web service (wsResponsesChannel). Again
this is used once for each response from the web service -->
<si:service-activator input-channel="wsResponsesChannel"
method="handleResponse" ref="responseProcessedFileService">
</si:service-activator>
【问题讨论】:
-
当它“什么都不做”的时候你能得到一个线程转储吗?使用 jstack 或 visualvm。此外,对于如此大量的文件,您可能应该使用默认
AcceptOnceFileListFilter以外的其他内容(或减少其容量),因为您最终会 OOM。 -
感谢您的评论,我已经进行了线程转储,看起来线程被锁定等待 1 个特定线程。还查看线程和监视堆似乎没有显示内存问题的迹象。 spring 文档中有一行声明,“轮询器和任务执行器,它们必须相互协调,否则你最终可能会造成人为的内存泄漏。”,想知道是不是这样。
-
你可以在某个地方发布线程转储(例如gist.github.com)吗?
-
嗨,加里,感谢您的帮助。我在以下网址上创建了 2 个要点,gist.github.com/robiulh/c02154c2c280d3900a66gist.github.com/robiulh/5213dc7300b1ed9cb1e8
标签: java spring spring-integration