Rajiv
Rajiv

Reputation: 602

Java Synchronization in web application

I have web application that generates the ODT file based on user request parameter and stored in the server as "mid.odt". After that it will be converted to Pdf and published to the user. Is there any synchronization issue will happen in here if more user will download the file with different parameter request.

Upvotes: 1

Views: 894

Answers (1)

rolfl
rolfl

Reputation: 17707

Yes, there is a problem. If two different users are processing files at the same time, then both will create the same file, and only one of them will be processed. Possible outcomes are:

  1. one, or both of the users will fail
  2. both users will apparently succeed, but perhaps they will not get the PDF of the file they requested.
  3. other outcomes are also possible.

You should be creating each download in to a unique file. File.createTempFile() is an option you can use, or perhaps, in Java8, use Files.createTempFile(...).

You will need to communicate to the ODT/PDF conversion process what the new file name is.

Upvotes: 2

Related Questions