Access file thread-safe in Java

Viewed 208

I'm really puzzled how little I can find on the web about this simple problem. I have build a webpage using Servlets and furthermore I'm using the quartz library to trigger cronjobs. I'm using the Files.copy method to handle the data.

In one of the cronjobs I download a file and copy it, in another one I copy this file, and on the webpage I display the file. How I prevent problems like accessing a file while it gets replaced?

My first idea was to create a class which has a static lock object which the other classes have to lock/sync before writing data. Does this make sense?

0 Answers
Related