/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.application.impl;

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.ThreadPoolExecutor;

/**
 * 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<T> extends TransferToEDTQueue<T> {
  private final ThreadPoolExecutor myExecutor;

  public TransferToPooledThreadQueue(@NonNls @NotNull String name,
                                     @NotNull Condition<?> shutUpCondition,
                                     int maxUnitOfWorkThresholdMs,
                                     @NotNull Processor<T> processor) {
    super(name, processor, shutUpCondition, maxUnitOfWorkThresholdMs);
    myExecutor = ConcurrencyUtil.newSingleThreadExecutor(name);
  }

  @Override
  protected void schedule(@NotNull Runnable updateRunnable) {
    myExecutor.execute(updateRunnable);
  }
}

@@ -711,31 +711,25 @@
 ij.util.
-ConcurrencyUtil
+Processor
 ;%0Aimport
@@ -739,39 +739,61 @@
 m.intellij.util.
-Process
+concurrency.BoundedTaskExecut
 or;%0Aimport com.i
@@ -918,16 +918,63 @@
 NotNull;
+%0Aimport org.jetbrains.ide.PooledThreadExecutor;
 %0A%0Aimport
@@ -995,26 +995,16 @@
 current.
-ThreadPool
 Executor
@@ -1399,18 +1399,8 @@
 nal 
-ThreadPool
 Exec
@@ -1791,33 +1791,38 @@
 r = 
-ConcurrencyUtil.newSing
+new BoundedTaskExecutor(Poo
 le
+d
 Thre
@@ -1831,21 +1831,28 @@
 Executor
-(name
+.INSTANCE, 1
 );%0A  %7D%0A%0A

use our common thread pool instead of a separate single thread pool