How to handle concurrency in Java servlets

In my servlet doPost method, I need to access the file (share) and update the file. How can I serve about 100 users using this at the same time?

Regards, Mithun

+3
source share
4 answers
  • Create a separate singleton class for accessing files.
  • Use Read and WriteLock from the java.util.concurent package to protect access to files.
  • Cache, so you won’t need to read the file if all you have to do is return the contents of the file.
+6
source

, - , ? - .

+3

With a high level of concurrency (for writing), synchronization will cost you a lot of bandwidth.

Databases are more adequate to handle this, if possible in your project.

+1
source

I would use the java.util.concurrent packages added in Java 1.5. In particular, BlockingQueue for the request queue and processing them in the second thread pool.

0
source

Source: https://habr.com/ru/post/1729901/


All Articles