public void run0() { FileSystemView fileSystem = filechooser.getFileSystemView(); if (loadThread.isInterrupted()) { return; } File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled()); if (loadThread.isInterrupted()) { return; } final Vector<File> newFileCache = new Vector<File>(); Vector<File> newFiles = new Vector<File>(); // run through the file list, add directories and selectable files to fileCache // Note that this block must be OUTSIDE of Invoker thread because of // deadlock possibility with custom synchronized FileSystemView for (File file : list) { if (filechooser.accept(file)) { boolean isTraversable = filechooser.isTraversable(file); if (isTraversable) { newFileCache.addElement(file); } else if (filechooser.isFileSelectionEnabled()) { newFiles.addElement(file); } if (loadThread.isInterrupted()) { return; } } } // First sort alphabetically by filename sort(newFileCache); sort(newFiles); newFileCache.addAll(newFiles); // To avoid loads of synchronizations with Invoker and improve performance we // execute the whole block on the COM thread DoChangeContents doChangeContents = ShellFolder.invoke( new Callable<DoChangeContents>() { public DoChangeContents call() { int newSize = newFileCache.size(); int oldSize = fileCache.size(); if (newSize > oldSize) { // see if interval is added int start = oldSize; int end = newSize; for (int i = 0; i < oldSize; i++) { if (!newFileCache.get(i).equals(fileCache.get(i))) { start = i; for (int j = i; j < newSize; j++) { if (newFileCache.get(j).equals(fileCache.get(i))) { end = j; break; } } break; } } if (start >= 0 && end > start && newFileCache .subList(end, newSize) .equals(fileCache.subList(start, oldSize))) { if (loadThread.isInterrupted()) { return null; } return new DoChangeContents( newFileCache.subList(start, end), start, null, 0, fid); } } else if (newSize < oldSize) { // see if interval is removed int start = -1; int end = -1; for (int i = 0; i < newSize; i++) { if (!newFileCache.get(i).equals(fileCache.get(i))) { start = i; end = i + oldSize - newSize; break; } } if (start >= 0 && end > start && fileCache .subList(end, oldSize) .equals(newFileCache.subList(start, newSize))) { if (loadThread.isInterrupted()) { return null; } return new DoChangeContents( null, 0, new Vector<>(fileCache.subList(start, end)), start, fid); } } if (!fileCache.equals(newFileCache)) { if (loadThread.isInterrupted()) { cancelRunnables(runnables); } return new DoChangeContents(newFileCache, 0, fileCache, 0, fid); } return null; } }); if (doChangeContents != null) { runnables.addElement(doChangeContents); SwingUtilities.invokeLater(doChangeContents); } }