So presumably if you use the NetCDF file cache, you have to do the
synchronization yourself, since you might be transparently sharing
file handles? That's an aspect of the cache that hadn't occurred to
me before...
Jon
On Mon, Sep 15, 2008 at 8:23 PM, John Caron <caron@xxxxxxxxxxxxxxxx> wrote:
> Hi Stuart:
>
> Underneath a Variable/NetcdfFile is (usually) a java.io.RandomAccessFile
> object, which is not thread-safe, because it keeps the state of the file
> position. So even if all you want to do is read data in multiple threads, you
> need to synchronize, typically on the NetcdFile object. Alternatively, open a
> new NetcdfFile for each thread. The Threads Data Server (TDS) uses a cache of
> open NetcdfFile files by using the NetcdfFile.acquire() method, which allows
> stateless handling of data requests minimizing file opening and closing..
>
>
> Stuart Maclean wrote:
>> Is ucar.nc2.Variable intended to be thread safe, at least for
>> Variables in 'read' mode?? If I do this:
>>
>> NetcdfFile nc = NetcdfFile.open( "foo.nc" );
>> Variable v = nc.findVariable( "v" );
>>
>> then can I do calls like
>>
>> Array a = v.read( "section Spec" );
>>
>> from many threads concurrently, with different sections obviously.
>>
>> Or is there state in a Variable that precludes this? I know I could
>> trawl the source code but that is slow.
>>
>> Apologies if this is a FAQ
>
> No, but I need to start a FAQ and put this into it!
>
> John
> _______________________________________________
> netcdf-java mailing list
> netcdf-java@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit:
> http://www.unidata.ucar.edu/mailing_lists/
>
--
Dr Jon Blower
Technical Director, Reading e-Science Centre
Environmental Systems Science Centre
University of Reading
Harry Pitt Building, 3 Earley Gate
Reading RG6 6AL. UK
Tel: +44 (0)118 378 5213
Fax: +44 (0)118 378 6413
j.d.blower@xxxxxxxxxxxxx
http://www.nerc-essc.ac.uk/People/Staff/Blower_J.htm