Java 正在使用spring集成轮询目录时创建新线程
这是我们的spring配置:Java 正在使用spring集成轮询目录时创建新线程,java,spring,multithreading,spring-integration,Java,Spring,Multithreading,Spring Integration,这是我们的spring配置: <int-file:inbound-channel-adapter id="fileReprocessorChannelId" channel="fileReprocessorChannel" directory="${file.location}" scanner="headScanner"> <int:poller cron="${reprocess.cronExpression}" max-messages-per-p
<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>
${reproces.maxMsgPerPoll}
${reproces.fileAgeInMillis}
在运行磁盘上有大约10000个文件的服务器时,当处理大约7000个文件时,我们会发现以下异常:java.nio.file.FileSystemException:打开的文件太多。
调试代码时,线程似乎在此处创建:
大量线程正在消耗大约70个线程的大量cpu,导致应用程序崩溃
如果有更好的方法(我们做错什么了吗?)或者这是spring代码中已知的错误,请您提供建议
编辑:
如果文件位于几个目录中,我建议使用。这可能也会启动一个线程,但对于目录,而不是目录中的每个文件。默认的
taskExecutor
是一个SyncTaskExecutor
,因此任务在调度程序线程上运行
默认的taskScheduler
bean只有10个线程,因此您必须有一些其他未显示的配置
您是否查看了线程转储(
jstack pid
)以查看所有这些线程都在做什么?这些线程似乎正在尝试锁定文件:java.lang.thread.State:WAITING(parking)at sun.misc.Unsafe.park(Native Method)-停止等待(java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)在java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)和java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.wait(AbstractQueuedSynchronizer.java:2039)中,我用整个配置更新了原始问题。这是70条线。我误解了lsof linux命令的用法。我在日志中得到了这个异常:java.nio.file.FileSystemException:打开的文件太多。打开的文件太多
:线程转储与Spring集成完全无关。这说明了春天的AMQP。你使用哪个版本?升级到最新版本怎么样:?我可以在没有spring amqp的情况下复制它。这是否相关?:java.lang.Thread.State:WAITING(驻车)at sun.misc.Unsafe.park(本机方法)-驻车等待(java.util.concurrent.locks.AbstractQueuedSynchronizer$Condit)java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)位于java.util.concurrent.locks.AbstractQueuedSynchronizer$Condit离子对象等待(节选)列队同步er.java:2039)