3

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

4 Answers 4

6
  • 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.
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.