How to lock a file on different application levels?

前端 未结 6 906
萌比男神i
萌比男神i 2021-01-05 17:01

Here\'s the scenario: I have a multi threaded java web application which is running inside a servlet container. The application is deployed multiple times inside the servlet

6条回答
  •  無奈伤痛
    2021-01-05 17:35

    The most simple solution is to create another process (web service or whatever is most simple to you). Only this process reads/writes the file and it listens to read/write requests by the other services.

    While it might seem that this is slower than using the network share directly, that's not necessarily the case: Using a network share means to use a client/server which is built into your OS (which does exactly that: send read/write requests to the server which offers the share).

    Since your service is optimized for the task (instead of being a general "serve file" service), it might even be faster.

提交回复
热议问题