0

I do not have not created any code yet on this topic so I will just ask a question.

I am making an application in which user will insert multiple paths, and in those paths/folders I will be searching for N biggest files in every folder separately. I was thinking that I should use new Thread for every path but I am not sure if this is a good practice or good idea in general.

One little subquestion - should I use TreeSet(RedBlack tree) to keep files in some kind of order or B-Tree would be better?

EDIT: By new Thread I mean using multiple threads with AsyncTask or something like that

user3086577
  • 101
  • 1
  • 10
  • 2
    There is only 1 filesystem and there can be only one operation on it at a time. Using multiple threads will most likely just make it slower. – zapl Jan 13 '14 at 15:43
  • So for example when downloading file from internet and copying something internally it just "jumps" from one thread to another to make it look like it works at once? – user3086577 Jan 13 '14 at 15:52
  • @zapl My understanding was that you can do concurrent reads. Is it the not the case here? I guess [this post](http://stackoverflow.com/questions/9746050/concurrent-file-access-in-android) kind of confuses me since it says that by default there are no lock unless you define them yourself? – Naveed Jan 13 '14 at 15:55
  • @Naveed huh, now I am really confused too. I do not need to actually write to file or something, just traverse the path which was set by user and look at the files size – user3086577 Jan 13 '14 at 16:00
  • I found http://stackoverflow.com/questions/6230029/multithread-file-search-c-sharp although It is in C# the idea of answer is same so I think @zapl is correct – user3086577 Jan 13 '14 at 16:03
  • 1
    Yes, you can access files concurrently but access happens sequentially down at hardware level. If 1 thread can already take all the available IO bandwidth then more than 1 thread will just add overhead. In case of downloads where the download speed is much slower than local file operations you wait most of the time on the downloads, so bottleneck is not the filesystem. In that case you can see increased overall speed by multithreading. @Naveed file locking / concurrent access is about preventing that multiple threads can modify files at the same time, which would be possible per default. – zapl Jan 13 '14 at 16:10

0 Answers0