I was trying to figure how File.renameTo()
works in Java and I reached the following method in UnixFileSystem.java
(I'm on macOS).
private native boolean rename0(File f1, File f2);
I understand that (please correct if I'm wrong) native
means JVM calls code/library written in another language. So, where/how can I or if it's possible see its implementation?
I'm curious to see its implementation as to confirm if I can use it for my following use case.
I need to run a Java application in two (or more) different servers which poll for files in the same directory (shared filesystem) and only one instance (server) should process a particular file. Whenever the application in any of the servers sees a file, it tries to move to some other directory and if the move is successful (determined by boolean returned by File.renameTo()
method), that server start processing on those file contents (batch processing to be precise). I did a quick test with three different instances polling a single directory (generating new files at 1000 files per second) and the results were as expected. I just want to confirm if it scales.
Note that I'm not moving the actual file but a zero-byte file named something like <actual-filename>.DONE
which is created after copying the file from source is complete.