Single thread pool vs one thread pool per task

后端 未结 3 1007
有刺的猬
有刺的猬 2021-01-20 04:39

I want to use concurrency in Java to make requests to an online API, download and parse the response documents, and load the resulting data into a database.

Is it st

3条回答
  •  青春惊慌失措
    2021-01-20 05:10

    One important thing to consider: does the order of the processing matter? i.e., is it important that the parsed result from the first download request gets loaded into the DB before the results from the second request?

    If so, you really need queues (or similar), one per task. In effect, three single-threaded thread "pools" (or use an ExecutorService).

    If not, @Brady makes good points. Unlike him, I'd probably make all three classes Runnable, but that doesn't mean you have to use three queues, you could still try a single pool and profile to see how it is working.

提交回复
热议问题