diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/TransferToPooledThreadQueue.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/TransferToPooledThreadQueue.java index 87de511bb733..5a8a590f1069 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/TransferToPooledThreadQueue.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/TransferToPooledThreadQueue.java @@ -15,27 +15,32 @@ */ package com.intellij.openapi.application.impl; -import com.intellij.concurrency.JobScheduler; import com.intellij.openapi.util.Condition; +import com.intellij.util.ConcurrencyUtil; import com.intellij.util.Processor; import com.intellij.util.containers.TransferToEDTQueue; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import java.util.concurrent.ScheduledThreadPoolExecutor; + /** - * Allows to process elements in the Application pooled thread. - * Processes elements in batches, no longer than 200ms per batch, and reschedules processing later for longer batches. + * Passes elements for processing in the dedicated thread. + * Processes elements in batches, no longer than {maxUnitOfWorkThresholdMs}ms per batch, and reschedules processing later for longer batches. * Usage: {@link #offer(Object)} } : schedules element for processing in a pooled thread */ public class TransferToPooledThreadQueue extends TransferToEDTQueue { - public TransferToPooledThreadQueue(@NotNull String name, - @NotNull Processor processorInEDT, + private final ScheduledThreadPoolExecutor myExecutor = ConcurrencyUtil.newSingleScheduledThreadExecutor("Encoding detection thread"); + + public TransferToPooledThreadQueue(@NonNls @NotNull String name, @NotNull Condition shutUpCondition, - int maxUnitOfWorkThresholdMs) { - super(name, processorInEDT, shutUpCondition, maxUnitOfWorkThresholdMs); + int maxUnitOfWorkThresholdMs, + @NotNull Processor processor) { + super(name, processor, shutUpCondition, maxUnitOfWorkThresholdMs); } @Override protected void schedule(@NotNull Runnable updateRunnable) { - JobScheduler.getScheduler().execute(updateRunnable); + myExecutor.execute(updateRunnable); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java index 5b7d4cbfadf3..c8f9d5f94ddf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/EncodingManagerImpl.java @@ -86,15 +86,18 @@ public class EncodingManagerImpl extends EncodingManager implements PersistentSt private static final Key CACHED_CHARSET_FROM_CONTENT = Key.create("CACHED_CHARSET_FROM_CONTENT"); private final TransferToPooledThreadQueue> myChangedDocuments = new TransferToPooledThreadQueue>( - "Loading documents", new Processor>() { - @Override - public boolean process(Reference ref) { - Document document = ref.get(); - if (document == null) return true; // document gced, don't bother - handleDocument(document); - return true; - } - }, ApplicationManager.getApplication().getDisposed(), -1); // drain the whole queue, do not reschedule + "Loading documents", + ApplicationManager.getApplication().getDisposed(), + -1, // drain the whole queue, do not reschedule + new Processor>() { + @Override + public boolean process(Reference ref) { + Document document = ref.get(); + if (document == null) return true; // document gced, don't bother + handleDocument(document); + return true; + } + }); public EncodingManagerImpl(EditorFactory editorFactory) { editorFactory.getEventMulticaster().addDocumentListener(new DocumentAdapter() {