File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Appending contents to one file from multiple threads

 
Jacob Sonia
Ranch Hand
Posts: 179
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a web application and all the requests and threads are writing to a single file. What is the best way to handle this. As far my understanding goes, the potential issues could be corruption of data ...
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest and safest approach would probably be to use a producer/consumer model where N threads insert their requests into a queue and 1 thread reads from that queue and writes to the file. If you use java.util.concurrent.ArrayBlockingQueue or java.util.concurrent.ConcurrentLinkedQueue, you wouldn't even have to handle the synchronization yourself.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic