0

I have a timer that updates (writing) a text file at fixed frequency. This file might be read upon request. Is the operation safe when the reading happens while the file is being updated? What should I do for this problem?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Junyong
  • 31
  • 1
  • 5
  • What did you try to solve it on your own? Also, please take a look at the [tour](http://stackoverflow.com/tour) and [how to ask](http://stackoverflow.com/help/how-to-ask). – moffeltje Jul 08 '15 at 14:00
  • File system characteristics are operating system specific, it is not really up to Java. Besides that, lets assume you use an operating system which properly supports concurrent reading and writing, it is still undefined if the operation is going to be "safe" as that is data specific. You will be able to read data sure, but if you get all the data you expect in a single read action, you can't know for sure. – Gimby Jul 08 '15 at 14:17
  • I think it should have no problem: take a look at this: http://stackoverflow.com/questions/4149/how-do-i-use-java-to-read-from-a-file-that-is-actively-being-written – Jegg Jul 08 '15 at 14:17

1 Answers1

-1

you can try create a class that is going to be responsible for the reading and writing of the resource, make it a singleton and access the read and write capabilities from different objects using Intrinsic Lock

Nikos
  • 387
  • 2
  • 15