1

The scenario is the following: I use a spring controller to read and edit single file on the file system. There are many user who can edit the file and many who can read that file. I don`t want to end up writing changes to the file while other users are reading from that file. I want multiple readers at a time or a single writer at a time. To achieve that I used ReentrantReadWriteLock (It allows multiple readers or a single writer at a time.).

BUT to use my ReentrantReadWriteLock I need to spawn my own threads that are synchronized on that lock. I found out that it is not a good idea to spawn custom threads in a Webcontainers.

Is there any good approach to achieve what I need ?

  • Take look also at http://stackoverflow.com/questions/1311050/transaction-mode-for-file-operations-in-java – MariuszS Jul 08 '14 at 20:17
  • The api seems depracted: "We have decided to move the project to dormant as we are convinced that the main advertised feature transactional file access can not be implemented reliably." – Satoshi Nakamoto Jul 08 '14 at 20:45
  • you can use the devOps process, create a lock file in the file system – Jaiwo99 Jul 08 '14 at 22:18
  • Can you be more specific please ? – Satoshi Nakamoto Jul 08 '14 at 22:35
  • After reading about the thread model of servlets:[1] And how spring controllers are allocated and managed:[2] I realized that: Web containers have a pool of threads and these threads are allocated per request. Spring beans/controllers are singletons by default. So threads are accessing the controller concurrently.I do not need to spawn my own threads. I just need to use the ReentrantReadWriteLock to sync. the "request" threads. [1]: http://tutorials.jenkov.com/java-servlets/servlet-concurrency.html [2]: http://www.codejava.net/frameworks/spring/understanding-spring-mvc – Satoshi Nakamoto Jul 09 '14 at 20:38

0 Answers0