mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Indexing diagnostics: workaround concurrent modification of statistics.
GitOrigin-RevId: f0007c29fec330e315eb3f85fba750725fbb73a4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bd31ae3093
commit
e506aacce9
+1
@@ -330,6 +330,7 @@ public final class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesU
|
||||
invokeConcurrentlyIfPossible(tasks);
|
||||
}
|
||||
|
||||
// TODO: this method may return earlier than all spawned threads have completed.
|
||||
public static void invokeConcurrentlyIfPossible(@NotNull List<? extends Runnable> tasks) {
|
||||
if (tasks.isEmpty()) return;
|
||||
if (tasks.size() == 1 || ApplicationManager.getApplication().isWriteAccessAllowed()) {
|
||||
|
||||
@@ -47,6 +47,7 @@ import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class UnindexedFilesUpdater extends DumbModeTask {
|
||||
@@ -332,6 +333,11 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
|
||||
|
||||
ConcurrentTasksProgressManager concurrentTasksProgressManager = new ConcurrentTasksProgressManager(indicator, providers.size());
|
||||
|
||||
// Workaround for concurrent modification of the [projectIndexingHistory].
|
||||
// PushedFilePropertiesUpdaterImpl.invokeConcurrentlyIfPossible may finish earlier than all its spawned tasks have completed.
|
||||
// And some scanning statistics may be tried to be added to the [projectIndexingHistory],
|
||||
// leading to ConcurrentModificationException in the statistics' processor.
|
||||
AtomicBoolean allTasksFinished = new AtomicBoolean();
|
||||
List<Runnable> tasks = ContainerUtil.map(providers, provider -> {
|
||||
SubTaskProgressIndicator subTaskIndicator = concurrentTasksProgressManager.createSubTaskIndicator(1);
|
||||
List<VirtualFile> files = new ArrayList<>();
|
||||
@@ -374,14 +380,20 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
|
||||
finally {
|
||||
scanningStatistics.setNumberOfSkippedFiles(thisProviderDeduplicateFilter.getNumberOfSkippedFiles());
|
||||
synchronized (projectIndexingHistory) {
|
||||
projectIndexingHistory.addScanningStatistics(scanningStatistics);
|
||||
if (!allTasksFinished.get()) {
|
||||
projectIndexingHistory.addScanningStatistics(scanningStatistics);
|
||||
}
|
||||
}
|
||||
subTaskIndicator.finished();
|
||||
}
|
||||
};
|
||||
});
|
||||
LOG.info("Scanning: use " + getNumberOfScanningThreads() + " scanning threads");
|
||||
PushedFilePropertiesUpdaterImpl.invokeConcurrentlyIfPossible(tasks);
|
||||
try {
|
||||
PushedFilePropertiesUpdaterImpl.invokeConcurrentlyIfPossible(tasks);
|
||||
} finally {
|
||||
allTasksFinished.set(true);
|
||||
}
|
||||
return providerToFiles;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user