I must program a webapp that let’s a user create and modify files.
Those files will be stored on the server. There are mainly two pages in this app : the first one lists the files the user is allowed to see. The user click on one of the item of this list : this let him go to the second page, where he can edit the file.
My problem is simple : I want to make sure that you cannot see, in the first page (list of every files) files that are currently being modified by another user (in the second page). The application is in Java EE using Struts 1 (I didn’t decide about that).
I’ve considered using a static List, for instance, that let me register every files that are currently opened ; I would put a file in the list when a user click and edit the file. In an ideal world, when the user save his work or goes back to the list, I would then remove the file from the list. However:
- This is not thread-safe
- What if a user just closed the browser?
What way would you proceed to solve this problem?
Thread safety is easily added to that scenario. The more important issue is that a file needs to be unlocked automatically once a user editing a file goes away, closes his browser, burns down his house or whatever. An automatic release of the file, coupled with some kind of refresh command sent from the browser periodically could solve this problem.