Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java file move high performance

Tags:

java

unix

storage

I am writing a media transcoding server in which I would need to move files in the filesystem and till now I am in the dilemma of whether using java renameTo can be replaced by something else that would give me better performance. I was considering using exec("mv file1 file2") but that would be my last bet. Anyone has had similar experiences or can help me find a solution?

like image 467
Ankur Chauhan Avatar asked Jan 22 '23 15:01

Ankur Chauhan


2 Answers

First of all, renameTo is likely just wrapping a system call.

Secondly, moving a file does not involve copying any data from the file itself (at least, in unix). All that happens is that the link from the old directory is removed, and a link from the new directory is added. I don't think you're going to find any performance improvements here.

like image 89
danben Avatar answered Jan 24 '23 06:01

danben


I don't think that using the default methods for file has a (mentionable) performance penalty as most of this JVMtoOS functions are wrapping native calls already.

The only case where an exec would be needed is if you wanted to do something with different rights than the program or use a special tool to copy/move the file. (e.g. smart-move when ntfs-junctions are involved)

like image 34
Johannes Wachter Avatar answered Jan 24 '23 06:01

Johannes Wachter