【发布时间】:2024-05-21 22:05:01
【问题描述】:
这是我们的 spring 配置:
<int-file:inbound-channel-adapter id="fileReprocessorChannelId" channel="fileReprocessorChannel"
directory="${file.location}" scanner="headScanner">
<int:poller cron="${reprocess.cronExpression}" max-messages-per-poll="${reprocess.maxMsgPerPoll}" />
</int-file:inbound-channel-adapter>
<int:chain id="reprocessorChain" input-channel="fileReprocessorChannel" output-channel="transformerChannel">
<int-file:file-to-string-transformer delete-files="false" charset="UTF-8" />
<int:header-enricher>
<int:header name="Operation" value="${operation.fileReprocessor}" overwrite="true" />
<int:header name="GUID" method="getGuidForReprocessing" ref="headerAttributesGenerator"/>
</int:header-enricher>
</int:chain>
<bean id="headScanner" class="FileStreamDirectoryScanner">
<constructor-arg>
<value>${reprocess.maxMsgPerPoll}</value>
</constructor-arg>
<constructor-arg>
<value>${reprocess.fileAgeInMillis}</value>
</constructor-arg>
<property name="locker" ref="nio-locker" />
</bean>
<bean id="nio-locker" class="org.springframework.integration.file.locking.NioFileLocker" />
<int:channel id="transformerChannel">
<int:interceptors>
<int:wire-tap channel="loggerChannel"/>
</int:interceptors>
</int:channel>
在磁盘上有大约 10000 个文件的服务器上运行时,当处理大约 7000 个文件时,我们发现以下异常:java.nio.file.FileSystemException: Too many open files.
大量线程正在消耗大约 70 个线程的大型 CPU,导致应用程序崩溃。
如果有更好的方法可以做到这一点(我们做错了什么?)或者这是 Spring 代码中的一个已知错误,您能否提出建议?
编辑:
- 附加的线程转储: Thread dump
【问题讨论】:
标签: java spring multithreading spring-integration