0

I am writing a multi threaded application in Java. I am using FileWriter to append to a single file across multiple threads.

The operation is append and the order is not important. So -

hello 1

bye 1

is same as -

bye 1

hello 1

but I do not wish to have a situation when the output is -

bye hello 1

1

My code (same in all the threads) -

            FileWriter fileWriter = new FileWriter(filePath, true);
            fileWriter.append(lineContent);
            fileWriter.close();

I could not find any information on the thread safety of FileWriter.append().

Any suggestions will be helpful.

Ankit Mishra
  • 474
  • 3
  • 11

0 Answers0