AsynchronousFileChannel.open() - is it blocking?
zhong.j.yu at gmail.com
Thu Mar 1 17:02:25 PST 2012
Yes, I'm asking whether during open() call, the thread can be
suspended due to slow external IO. Same goes to size() and truncate().
Since the class is labeled as "Asynchronous", one might overlook the
fact that some methods could suspend the calling thread. If one is
writing a so called asynchronous web server for example, such methods
must be invoked specially. It might be worthwhile to put the fact in
Pardon me if the answer is too obvious.But I didn't see definitively
why open() couldn't always return immediately, by bundling any IO
actions involved to later read/write actions. For example, if it takes
a while to discover that the file doesn't exist, the error can be
raised after open(), in a completion handler for a read/write. I would
prefer this mode.
On Thu, Mar 1, 2012 at 6:10 PM, Vitaly Davidovich <vitalyd at gmail.com> wrote:
> I'm not sure what distinction you're trying to draw in async/sync vs
> non-blocking/blocking. Can you clarify that part? In general, non-blocking
> is analogous to async and blocking to synchronous in terms of whether the
> caller is blocked or not -- you can certainly have a synchronous/blocking
> call that's actually implemented asynchronously internally, but from the
> caller's perspective it's a blocking call as control does not return until
> the method completes.
> Are you instead asking whether any physical i/o will be triggered?
> On Thu, Mar 1, 2012 at 6:52 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
>> A synchronous action can be blocking or non-blocking. I'm asking the
>> blocking aspect.
>> On Thu, Mar 1, 2012 at 5:02 PM, Vitaly Davidovich <vitalyd at gmail.com>
>> > It's probably safe to assume that any method that doesn't return a
>> > Future or
>> > accepts a CompletionHandler runs synchronously.
>> > On Thu, Mar 1, 2012 at 5:52 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
>> >> Is open() a potentially blocking action? Apparently so because some
>> >> sanity checking (e.g. existence of the file) requires disk spin. If
>> >> that's the case, it should probably be explicitly documented.
>> >> And after open(), are following methods blocking or non-blocking?
>> >> size();
>> >> truncate();
>> >> Thanks,
>> >> Zhong Yu
More information about the nio-dev