限制多个执行程序中的总线程数

时间:2020-12-12 17:30:55

I have a six processes that send data to external servers. Each process runs multiple "Transfer" threads to improve performance and paralellism (latencies, big files, etc.). I have one executor per process with 5 threads max each.

我有六个进程将数据发送到外部服务器。每个进程都运行多个“传输”线程,以提高性能和并行性(延迟,大文件等)。每个进程有一个执行程序,每个进程最多5个线程。

Now, since the external server supports only 20 threads, and my processes try to run 30 total threads (6 processes x 5 threads each), some threads crash. I get it.

现在,由于外部服务器只支持20个线程,并且我的进程尝试运行30个总线程(6个进程x 5个线程),一些线程崩溃。我知道了。

Is there any way of creating a "big thread pool" (with 20 threads) in Java to limit the total transfer threads to a maximum of 20 for all processes?

是否有任何方法可以在Java中创建“大线程池”(包含20个线程),以便将所有进程的总传输线程限制为最多20个?

Alternatively, I was thinking of creating a single executor for all processes but then one process could hog all threads, leaving the other ones starving.

或者,我正在考虑为所有进程创建一个执行程序,但是一个进程可能会占用所有线程,而其他进程则会挨饿。

1 个解决方案

#1


2  

You can use single executor and implement bulkhead pattern for your processes. Hystrix and Resilience4j have ready implementations, for example.

您可以使用单个执行程序并为您的进程实现隔板模式。例如,Hystrix和Resilience4j已经准备好了。

#1


2  

You can use single executor and implement bulkhead pattern for your processes. Hystrix and Resilience4j have ready implementations, for example.

您可以使用单个执行程序并为您的进程实现隔板模式。例如,Hystrix和Resilience4j已经准备好了。