• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Threads for File Copy  RSS feed

 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I use multiple threads for copying a single large file from one directory to another. Will it result in increased speed and is it feasable?

Has anybody tried that?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fastest way to copy one big file is to do it sequentially - because everything else would force the harddisk read/write heads to hop around, which would likely slow it down significantly.

If you are not using NIO, you should give *that* a try: http://javaalmanac.com/egs/java.nio/File2File.html
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Ilja]: The fastest way to copy one big file is to do it sequentially - because everything else would force the harddisk read/write heads to hop around, which would likely slow it down significantly.

In general I agree. However some filesystems use data striping, in which case it may be possible to benefit from using multiple threads. Ideally if each thread were copying from one drive to another drive, with no overlap between threads, It's also possible that in this situation, using FileChannel's transferTo() will ultimately invoke native code that is equivalent to using multiple threads. (I would argue that's what a well-designed striped filesystem should do, in my briefly-considered opinion, but I have no idea if that's what they actually do do.

Anyway, yeah, I second the recommendation for FileChannel's transferTo(). I'd only try multithreaded copies here if I knew that there was indeed a striped filesystem involved. And I'd be sure to test later to see if there was any real improvement over transferTo().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!