SimpleFileVisitor зависает в каталоге сетевого диска, несмотря на SKIP_SUBTREE

У меня проблема с очень медленным сетевым диском и SimpleFileVisitorкоторый должен пропустить его, но также зависает. Полагаю, проблема в чтении атрибутов файла. Есть ли встроенный способ просто смотреть на путь и игнорировать все остальное, чтобы быть как можно быстрее?

          final FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
        private final PathMatcher matcherDirs = FileSystems.getDefault().getPathMatcher(PATTERN_DIRS);

        @Override
        public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
            if (!matcherDirs.matches(dir)) {
                logger.trace("skipping directory {}", dir.toString());
                return FileVisitResult.SKIP_SUBTREE;
            }

            logger.debug("visit directory {}", dir.toString());
            return FileVisitResult.CONTINUE;
        }

    };

Созданный журнал:

      2021-06-10 10:10:08,137 | TRACE | skipping directory /ap/os/script
2021-06-10 10:10:08,137 | TRACE | skipping directory /at
2021-06-10 10:10:18,143 | TRACE | skipping directory /backups
2021-06-10 10:10:18,143 | TRACE | skipping directory /dev

Листинг только каталога - это быстро, но просмотр его - медленный процесс. Так что посетитель тоже мог быть быстрым, ИМХО.

      $ time ls -dl /backups
dr-xr-xr-x    1 root     system            1 Jan 06 15:54 /backups
real    0m0.005s
user    0m0.000s
sys     0m0.001s

$ time ls -l /backups 
total 0
real    0m30.015s
user    0m0.000s
sys     0m0.001s

0 ответов

Другие вопросы по тегам