• Post Reply Bookmark Topic Watch Topic
  • New Topic

file operations thread-safe within servlets/JSP?  RSS feed

 
Toby Davis
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably already answered myself with this question, but here it goes...
Are file I/O operations, such as reading/writing files using standard java.io.* filestreaming, fall under the umbrealla of servlet thread-safety as long as its written within a servlet's service-based methods or in the JSP itself (where it compiles into a servlet in the app engine)?
Again, this assumes no class (non-static) variables are being used and no application-level objects are being altered, etc. Also assumes file-locking has been considered and trapped for.
---
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For all practical purposes, just act like your servlets were ordinary asynchronous threads and code appropriately.
That is, if instance 1 of servlet A wants to write to a file and so does instance 2, you have to guard the file the same way as if they were any other threads attempting file I/O.
 
Toby Davis
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For this particular app, total number of users is less than 50, and each file written has a unique name (as guaranteed as possible with 50 ppl).
Will two File objects being read/written cross threads even though each object was instantiated with unique names?
I had thought each filestreaming to a specific File object instantiated within a thread in the servlet would occur within that thread and not crossover to another thread (user) in the same servlet?
Want to be sure I don't do overkill on sychronization in file I/O if the above is true...
Am I making sense?
---
[ October 22, 2002: Message edited by: Toby Davis ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although each file is unique to each user, you have to watch out for the possiblilty that a user can have more than one request being processed at the same time. That might be due to multiple clicks on a submit button, use of frames, or multiple browser windows open.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!