我正在根据数据库中的数据创建动态集成流。
我们需要用文件名模式轮询的目录在数据库中
例如
Instance, directory , filename
ABC , c:/input1 , test.txt
DEF , d:/input2 , fresh.xlsx
我有大约200-300个条目,所以我正在做的是为每个记录创建集成流,因为它将有不同的处理器等
对于每条记录
IntegrationFlowBuilder flowBuilder =
IntegrationFlows
.from(new CustomFileReadingSource(input), consumer);
flowBuilder.transform(new ObjectToJsonTransformer());
flowBuilder.handle(o -> {
// System.out.println(o.getPayload());
});
context.registration(flowBuilder.get()).register();
一旦所有线程都注册了,但当我查看VisualVM或日志时,我只看到8-10个线程,而不是100或200个。
从日志
2018-11-13 16:00:41.399 [task-scheduler-3] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:41.587 [task-scheduler-10] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:41.807 [task-scheduler-4] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:42.071 [task-scheduler-5] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:42.323 [task-scheduler-7] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:42.569 [task-scheduler-6] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:42.878 [task-scheduler-8] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:43.197 [task-scheduler-9] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:43.588 [task-scheduler-1] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:43.951 [task-scheduler-2] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:44.305 [task-scheduler-3] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:44.598 [task-scheduler-10] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:45.031 [task-scheduler-4] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:45.414 [task-scheduler-5] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
2018-11-13 16:00:45.974 [task-scheduler-7] INFO c.b.m.p.f.b.LoggerSourceAdvisor.afterReceive(32)
正如你所看到的,它只有几个线程在轮询线程
有人能解释一下为什么它没有创建线程或任何更好的方法来实现并行轮询吗?
Polling Ednpoints
都基于预定义的全局ThreadPoolTaskScheduler
,默认情况下10
为池大小:https://docs.spring.io/spring-integration/docs/5.1.0.RELEASE/reference/html/configuration.html#namespace-任务调度程序
另一方面,在CPU最多为16核的情况下,尝试拥有100个线程是毫无意义的。生成更多的线程甚至可能导致应用程序的速度减慢。
请参阅文档。
默认调度程序只有10个线程。通常情况下,计划任务是短时间运行的,在这种情况下,这通常就足够了;如果没有,则增加线程数或添加一个任务执行器,以便调度程序将工作交给另一个线程。