• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

file operations thread-safe within servlets/JSP?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
---
 
Saloon Keeper
Posts: 27819
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic