views:

312

answers:

4

Hello ,

In my doPost method of the servlet I need to access a file (shared resource ) and update the file . How do I cater to some 100 users using this at the same time ?

Regards, Mithun

+5  A: 
  • Create separate singleton class for file access.
  • Use Read and WriteLock from java.util.concurent package to protect file access.
  • Cache, so that you won't have to do file read if all you have to do is to return file content.
Dev er dev
+3  A: 

Are you sure a file is how you want to handle this? Protecting access to data by multiple concurrent users is most of what a modern database does.

Licky Lindsay
+1  A: 

With high level of concurrency (for writes), synchronizing will cost you a lot of throughput.

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

KLE
A: 

I would take advantage of the java.util.concurrent packages added in Java 1.5. Specifically a BlockingQueue to queue up requests and handle them in a second pool of threads.

dj_segfault