In accordance with this question, small files added to Windows are atomic.
I am trying to use this in Scala / Java to avoid blocking when adding a small int to the file.
I find that recordings using FileOutputStream(..., true)from multiple threads alternate, although a related question suggests that they should be atomic.
The rigidity for this in Scala can be found in my github
key code:
def invoked(id: Int, path: String) = {
val writer = new FileOutputStream(path, true)
val bytes = (id.toString + ';').getBytes(Charset.defaultCharset())
writer.write(bytes)
writer.close()
}
... I was hoping that "invoked" would be thread safe without blocking.
The same Java / Scala code reaches the atomic file that is added to Linux (on this question adds small files, atoms on POSIX), so the difference seems to be in native implementations FileOutputStream.
Perhaps FileOutputStreamdoes not pass the correct flags on Windows? Does anyone know how to make this work? Do I have to write a JNI DLL to make this work, or can I do it using standard Java libraries?
source
share