A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Threads and Synchronization
Appending contents to one file from multiple threads
Joined: Jun 28, 2009
Mar 28, 2013 21:59:22
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 ...
Joined: Jan 03, 2004
Mar 29, 2013 10:10:56
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
, you wouldn't even have to handle the synchronization yourself.
I agree. Here's the link:
subject: Appending contents to one file from multiple threads
Should lock methods be callable by the client
long post IBM.158
IBM HttpServer and websphere Appserver
NX: [URLyBird] Problem about synchronize mechanism
000-341 sample test questions
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015