How to list a 2 million files directory in java without having an “out of memory” exception

后端 未结 15 1839
挽巷
挽巷 2020-12-06 00:04

I have to deal with a directory of about 2 million xml\'s to be processed.

I\'ve already solved the processing distributing the work between machines and threads us

15条回答
  •  甜味超标
    2020-12-06 00:42

    Why do you store 2 million files in the same directory anyway? I can imagine it slows down access terribly on the OS level already.

    I would definitely want to have them divided into subdirectories (e.g. by date/time of creation) already before processing. But if it is not possible for some reason, could it be done during processing? E.g. move 1000 files queued for Process1 into Directory1, another 1000 files for Process2 into Directory2 etc. Then each process/thread sees only the (limited number of) files portioned for it.

提交回复
热议问题