diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index 0d69ad3a05e5..8a7662509546 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -17,7 +17,6 @@ package com.intellij.util.indexing; import com.intellij.AppTopics; -import com.intellij.concurrency.JobScheduler; import com.intellij.history.LocalHistory; import com.intellij.ide.caches.CacheUpdater; import com.intellij.lang.ASTNode; @@ -50,6 +49,7 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; +import com.intellij.openapi.vfs.newvfs.persistent.FlushingDaemon; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import com.intellij.psi.*; import com.intellij.psi.impl.PsiDocumentTransactionListener; @@ -82,7 +82,6 @@ import java.io.*; import java.util.*; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; @@ -313,19 +312,15 @@ public class FileBasedIndex implements ApplicationComponent { }); //FileUtil.createIfDoesntExist(workInProgressFile); saveRegisteredIndices(myIndices.keySet()); - myFlushingFuture = JobScheduler.getScheduler().scheduleAtFixedRate(new Runnable() { + myFlushingFuture = FlushingDaemon.everyFiveSeconds(new Runnable() { int lastModCount = 0; public void run() { if (lastModCount == myLocalModCount) { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - public void run() { - flushAllIndices(); - } - }); + flushAllIndices(); lastModCount = myLocalModCount; } } - }, 5000, 5000, TimeUnit.MILLISECONDS); + }); } } @@ -621,31 +616,24 @@ public class FileBasedIndex implements ApplicationComponent { } } - private volatile boolean flushRunning = false; private void flushAllIndices() { - if (flushRunning || HeavyProcessLatch.INSTANCE.isRunning()) return; - flushRunning = true; + if (HeavyProcessLatch.INSTANCE.isRunning()) return; - try { - IndexingStamp.flushCache(); - for (ID indexId : new ArrayList>(myIndices.keySet())) { - if (HeavyProcessLatch.INSTANCE.isRunning()) { - return; - } - try { - final UpdatableIndex index = getIndex(indexId); - if (index != null) { - index.flush(); - } - } - catch (StorageException e) { - LOG.info(e); - requestRebuild(indexId); + IndexingStamp.flushCache(); + for (ID indexId : new ArrayList>(myIndices.keySet())) { + if (HeavyProcessLatch.INSTANCE.isRunning()) { + return; + } + try { + final UpdatableIndex index = getIndex(indexId); + if (index != null) { + index.flush(); } } - } - finally { - flushRunning = false; + catch (StorageException e) { + LOG.info(e); + requestRebuild(indexId); + } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java index 510f34b50677..edc1a9f720dc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java @@ -19,7 +19,6 @@ */ package com.intellij.openapi.vfs.newvfs.persistent; -import com.intellij.concurrency.JobScheduler; import com.intellij.openapi.Forceable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; @@ -47,7 +46,6 @@ import javax.swing.*; import java.awt.*; import java.io.*; import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; @SuppressWarnings({"PointlessArithmeticExpression", "HardCodedStringLiteral"}) public class FSRecords implements Forceable { @@ -305,20 +303,16 @@ public class FSRecords implements Forceable { } private static void setupFlushing() { - myFlushingFuture = JobScheduler.getScheduler().scheduleAtFixedRate(new Runnable() { + myFlushingFuture = FlushingDaemon.everyFiveSeconds(new Runnable() { int lastModCount = 0; public void run() { if (lastModCount == ourLocalModificationCount) { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - public void run() { - flushSome(); - } - }); + flushSome(); } lastModCount = ourLocalModificationCount; } - }, 5000, 5000, TimeUnit.MILLISECONDS); + }); } public static void force() { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FlushingDaemon.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FlushingDaemon.java new file mode 100644 index 000000000000..a046153fdbca --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FlushingDaemon.java @@ -0,0 +1,20 @@ +/* + * @author max + */ +package com.intellij.openapi.vfs.newvfs.persistent; + +import com.intellij.util.ConcurrencyUtil; + +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class FlushingDaemon { + private static final ScheduledThreadPoolExecutor pool = ConcurrencyUtil.newSingleScheduledThreadExecutor("Flushing thread"); + + private FlushingDaemon() {} + + public static ScheduledFuture everyFiveSeconds(Runnable r) { + return pool.scheduleAtFixedRate(r, 5, 5, TimeUnit.SECONDS); + } +}