How to choose thread pool size?

大憨熊 提交于 2019-12-24 12:24:35

问题


Suppose I have to read, process and update a lot of files in Java. I am going to use one computer with 16 cores. Since I have both IO-bound (read and update files) and CPU-bound (processing) tasks I allocate 2 thread pools.

I would allocate one pool for CPU-bound tasks with 16 threads (the number of threads == the number of CPUs). Now I wonder what the IO-bound pool size is. Thread pools of what sizes would you suggest ?


回答1:


It would depend on your storage capabilities and what kinds of IO you are trying to do. For example, long sequential writes on harddisks would favor a single IO thread, but you would want to scale this according to your requirements.

In this answer, https://stackoverflow.com/a/2821025/2855891, BlackAura explains why experimentation and profiling is probably the only way you can really find out.

There are probably already very good articles on this topic.



来源:https://stackoverflow.com/questions/19375795/how-to-choose-thread-pool-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!