Java multithreaded file downloading performance

前端 未结 4 1803
难免孤独
难免孤独 2020-12-13 10:24

Having recently worked on a project which required some more IO interaction than I\'m used to, I felt like I wanted to look past the regular libraries (Commons IO, in partic

4条回答
  •  遥遥无期
    2020-12-13 11:06

    To answer my own questions:

    1. The increased CPU usage was due to a while() {} loop that was waiting for the threads to finish. As it turns out, awaitTermination is a much better alternative to wait for an Executor to finish :)
    2. (And 3 and 4) This seems to be the nature of the beast; in the end I achieved what I wanted to do by using careful synchronization of the different threads that each download a chunk of data (well, in particular the writes of these chunks back to disk).

提交回复
热议问题