Re: Concurrency and file writing

2009-02-16 Thread Jeff Rose
I think it depends on whether this is CPU or IO bound, where the files will be stored and how expensive it is to generate blocks, check for existence, copy etc. Over a distributed filesystem running across data-centers the decision will probably be different than on a multi-core cpu on a sing

Re: Concurrency and file writing

2009-02-15 Thread Shawn Hoover
On Sat, Feb 14, 2009 at 5:44 PM, James Reeves wrote: > > On Feb 14, 5:30 pm, Dan wrote: > > What about making the file an agent and sending write actions to it? > > I don't see how that would solve the problem, unless you're suggesting > that I have a single agent to handle all reads and writes?

Re: Concurrency and file writing

2009-02-15 Thread Laurent PETIT
Yes, and combined with the technique in the link Kevin provided, it's clean if something goes wrong, java/the os will take care of deleting the temp file for you : // Create temp file. File temp = File.createTempFile(*"pattern"*, *".suffix"*); // Delete temp file when program exits. temp.deleteOn

Re: Concurrency and file writing

2009-02-15 Thread James Reeves
On Feb 15, 12:42 pm, Laurent PETIT wrote: > Well, so indeed, the temporary file solution seems a good one, then. The consensus seems to be to use a temporary file, then. I had thought there might be a flashy cutting-edge way of handling this sort of IO, but I guess sometimes the best solutions a

Re: Concurrency and file writing

2009-02-15 Thread Laurent PETIT
Well, so indeed, the temporary file solution seems a good one, then. -- laurent 2009/2/15 James Reeves > > On Feb 14, 10:58 pm, Laurent PETIT wrote: > > You could maybe solve the read problem by also embedding, in the name of > the > > file, its intended content size ? > > That solves the rea

Re: Concurrency and file writing

2009-02-15 Thread James Reeves
On Feb 14, 10:58 pm, Laurent PETIT wrote: > You could maybe solve the read problem by also embedding, in the name of the > file, its intended content size ? That solves the read problem, but not the conflicting write problem. It also seems harder than using a temporary file. > If the file is im

Re: Concurrency and file writing

2009-02-14 Thread Kevin Downey
http://www.exampledepot.com/egs/java.io/CreateTempFile.html On Sat, Feb 14, 2009 at 4:38 PM, Mark H. wrote: > > On Feb 14, 6:48 am, James Reeves wrote: >> I've been having some difficulty coming up with a scheme for writing >> to files in a thread-safe manner. The files are named with the hash

Re: Concurrency and file writing

2009-02-14 Thread Mark H.
On Feb 14, 6:48 am, James Reeves wrote: > I've been having some difficulty coming up with a scheme for writing > to files in a thread-safe manner. The files are named with the hash of > their content, so they are effectively immutable. > > The problem comes with writing them for the first time. I

Re: Concurrency and file writing

2009-02-14 Thread Laurent PETIT
Hello, You could maybe solve the read problem by also embedding, in the name of the file, its intended content size ? So it could be reasonably cheap to check if a file is present but not yet totally flushed to the disk by comparing its intended size (from its name) and its current real size ? F

Re: Concurrency and file writing

2009-02-14 Thread James Reeves
On Feb 14, 5:30 pm, Dan wrote: > What about making the file an agent and sending write actions to it? I don't see how that would solve the problem, unless you're suggesting that I have a single agent to handle all reads and writes? - James --~--~-~--~~~---~--~~ Y

Re: Concurrency and file writing

2009-02-14 Thread Dan
On Sat, Feb 14, 2009 at 9:48 AM, James Reeves wrote: > > Hi folks, > > I've been having some difficulty coming up with a scheme for writing > to files in a thread-safe manner. The files are named with the hash of > their content, so they are effectively immutable. > What about making the file an