我正在基于数据库中的数据创建动态集成流。
我们需要用文件名模式查询的目录在数据库中
例如
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)
如您所见,只有少数几个线程正在轮询线程
有人可以帮忙为什么它不创建线程或没有更好的方法来实现并行轮询器吗?
答案 0 :(得分:2)
是的。因为所有Polling Ednpoints
都基于预定义的全局ThreadPoolTaskScheduler
,默认情况下10
作为池大小:https://docs.spring.io/spring-integration/docs/5.1.0.RELEASE/reference/html/configuration.html#namespace-taskscheduler
另一方面,尝试拥有100个线程却毫无意义,而您的CPU最多有16个内核。占用更多线程甚至可能导致应用程序变慢。
答案 1 :(得分:1)
默认调度程序只有10个线程。通常,计划任务运行时间短,在这种情况下,这通常就足够了;如果不是,请增加线程数或添加任务执行程序,以便调度程序将工作移交给另一个线程。