java.nio.file.Files.isReadable() slow on Windows 7

Zhong Yu zhong.j.yu at gmail.com
Fri May 11 07:29:13 PDT 2012


On Fri, May 11, 2012 at 2:32 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 11/05/2012 04:09, Zhong Yu wrote:
>>
>> java.nio.file.Files.isReadable() seems to be really slow on Windows 7;
>> on my machine it takes 3ms per call (tested in a tight loop on the
>> same file). That means only 300 calls per second.
>>
>> It's much faster to test readability by opening a file channel for
>> read then close it.
>>
>> Any other workarounds?
>>
>> Zhong Yu
>
> Oops, I thought we had put in a fast path for the check read case. The
> background to this is that checking access to a file on Windows is very
> expensive because it requires reading the DACL and determining the user's
> effective access.
>
> I don't have time to check a Windows machine just at the minute but can you
> change:
>
> Files.isReadable(path)
>
> to
>
> path.getFileSystem().provider().checkAccess(path)

yes it works, this one takes only 0.02ms!

> in your test, re-run and tell us if this fixes the issue. I suspect it will
> because checkAccess has a fast path for the check read case, and that fast
> path doesn't take correctly take access of the isReadable usage.
>
> -Alan.


More information about the nio-dev mailing list