How many threads should I use in my Java program?

前端 未结 7 1286
日久生厌
日久生厌 2020-12-09 18:03

I recently inherited a small Java program that takes information from a large database, does some processing and produces a detailed image regarding the information. The ori

7条回答
  •  抹茶落季
    2020-12-09 18:45

    The number that your application needs; no more, and no less.

    Obviously, if you're writing an application which contains some parallelisable algorithm, then you can probably start benchmarking to find a good balance in the number of threads, but bear in mind that hundreds of threads won't speed up any operation.

    If your algorithm can't be parallelised, then no number of additional threads is going to help.

提交回复
热议问题