Returns the canonical instance of the {@link WorkQueue} to be used in
running concurrent tasks, ensuring the <i>at least</i> the specified
number of threads are available.
1487
public static WorkQueue getWorkQueue(int numThreads) {
        if (singleton == null) {
            synchronized (WorkQueue.class) {
                if (singleton == null)
                    singleton = new WorkQueue(numThreads); 
            }
        }

        while (singleton.availableThreads() < numThreads) {
            singleton.addThread();
        }
        return singleton;
    }
846543
public static ExecutorService getQueueingExecutorService(final Queue<Runnable> taskQueue) {
        return new ExecutorService() {
            @Override
            public void execute(Runnable command) {
                taskQueue.offer(command);
            }

            @Override
            public void shutdown() {
                throw new UnsupportedOperationException();
            }

            @Override
            public List<Runnable> shutdownNow() {
                throw new UnsupportedOperationException();
            }

            @Override
            public boolean isShutdown() {
                return false;
            }

            @Override
            public boolean isTerminated() {
                return false;
            }

            @Override
            public boolean awaitTermination(long timeout, TimeUnit unit)
                    throws InterruptedException {
                return true;
            }

            @Override
            public <T> Future<T> submit(Callable<T> task) {
                Preconditions.checkNotNull(task);
                FutureTask<T> retval = new FutureTask<T>(task);
                taskQueue.offer(retval);
                return retval;
            }

            @Override
            public <T> Future<T> submit(Runnable task, T result) {
                Preconditions.checkNotNull(task);
                FutureTask<T> retval = new FutureTask<T>(task, result);
                taskQueue.offer(retval);
                return retval;
            }

            @Override
            public Future<?> submit(Runnable task) {
                Preconditions.checkNotNull(task);
                ListenableFutureTask<Object> retval = ListenableFutureTask.create(task, null);
                taskQueue.offer(retval);
                return retval;
            }

            @Override
            public <T> List<Future<T>> invokeAll(
                    Collection<? extends Callable<T>> tasks)
                    throws InterruptedException {
                throw new UnsupportedOperationException();
            }

            @Override
            public <T> List<Future<T>> invokeAll(
                    Collection<? extends Callable<T>> tasks, long timeout,
                    TimeUnit unit) throws InterruptedException {
                throw new UnsupportedOperationException();
            }

            @Override
            public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
                    throws InterruptedException, ExecutionException {
                throw new UnsupportedOperationException();
            }

            @Override
            public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
                    long timeout, TimeUnit unit) throws InterruptedException,
                    ExecutionException, TimeoutException {
                throw new UnsupportedOperationException();
            }
        };
    }
931415
protected MultiThreadedWorker getMultiThreadedWorker(SelectionKey key, long threadIdfWQM) {

        MultiThreadedWorker worker = null;
        synchronized (multiThreadedObjectPool) {
            worker = (MultiThreadedWorker) multiThreadedObjectPool.get();
        }

        if (worker == null) {
            worker = new MultiThreadedWorker(this);
        }

        worker.set(key);
        return worker;
    }
882154
private List<Runnable> drainQueue() {
        BlockingQueue<Runnable> q = workQueue;
        ArrayList<Runnable> taskList = new ArrayList<>();
        q.drainTo(taskList);
        if (!q.isEmpty()) {
            for (Runnable r : q.toArray(new Runnable[0])) {
                if (q.remove(r))
                    taskList.add(r);
            }
        }
        return taskList;
    }
38648
public static ExecutorService newWorkStealingPool() {
        return new ForkJoinPool
            (Runtime.getRuntime().availableProcessors(),
             ForkJoinPool.defaultForkJoinWorkerThreadFactory,
             null, true);
    }
1296083
@Beta
  @GwtIncompatible // concurrency
  public static ThreadFactory platformThreadFactory() {
    if (!isAppEngine()) {
      return Executors.defaultThreadFactory();
    }
    try {
      return (ThreadFactory)
          Class.forName("com.google_voltpatches.appengine.api.ThreadManager")
              .getMethod("currentRequestThreadFactory")
              .invoke(null);
    } catch (IllegalAccessException e) {
      throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e);
    } catch (InvocationTargetException e) {
      throw Throwables.propagate(e.getCause());
    }
  }
85571
public Queue<PoolSchedulable> getPreemptQueue() {
    // TODO: For now, we support only one kind of scheduling.
    // Also note that FAIR is PRIORITY with equal priorities (by default)
    ScheduleComparator sPreempt = null;
    if (preemptQueue == null) {
      ScheduleComparator sc = configManager.getPoolGroupComparator(getName());
      if (sc == ScheduleComparator.PRIORITY) {
        sPreempt = ScheduleComparator.PRIORITY_PREEMPT;
      } else {
        throw new IllegalArgumentException("Unknown/misconfigured poolgroup");
      }
      preemptQueue = createPoolQueue(sPreempt);
    }
    return preemptQueue;
  }
790178
protected Queue<AsyncResourceRequest<V>> getRequestQueueForKey(K key) {
        Queue<AsyncResourceRequest<V>> requestQueue = requestQueueMap.get(key);
        if(requestQueue == null) {
            Queue<AsyncResourceRequest<V>> newRequestQueue = new ConcurrentLinkedQueue<AsyncResourceRequest<V>>();
            requestQueue = requestQueueMap.putIfAbsent(key, newRequestQueue);
            if(requestQueue == null) {
                requestQueue = newRequestQueue;
            }
        }
        return requestQueue;
    }
607362
public synchronized ExecutorService getBatchThreadPool() {
    if (batchThreadPool == null) {
      batchThreadPool = Executors
          .newCachedThreadPool(ThreadUtil.getThreadFactory(BATCH_POOL_THREAD_NAME_PATTERN, true));
    }
    return batchThreadPool;
  }
1104369
protected Queue<Object> getWorkQueue() {
        synchronized (this.queueLock) {
            // swap the primary and secondary queues
            Queue<Object> tmp = this.workQueue1;
            this.workQueue1 = this.workQueue2;
            this.workQueue2 = tmp;
            return tmp;
        } // end-sync
    }
598372
@Override
    public BlockingQueue<Work> getWorkQueue() {

        BlockingQueue<Work> queue = new LinkedBlockingQueue<Work>();
        BlockingQueue<Runnable> workQueue = executor.getQueue();
        for (Runnable r: workQueue) {
            if (r instanceof EventWorker) {
                queue.add(((EventWorker)r).work);
            }
        }

        return queue;
    }
599014
private WorkQueue findNonEmptyStealQueue(WorkQueue w) {
        // Similar to loop in scan(), but ignoring submissions
        int r = w.seed; r ^= r << 13; r ^= r >>> 17; w.seed = r ^= r << 5;
        int step = (r >>> 16) | 1;
        for (WorkQueue[] ws;;) {
            int rs = runState, m;
            if ((ws = workQueues) == null || (m = ws.length - 1) < 1)
                return null;
            for (int j = (m + 1) << 2; ; r += step) {
                WorkQueue q = ws[((r << 1) | 1) & m];
                if (q != null && !q.isEmpty())
                    return q;
                else if (--j < 0) {
                    if (runState == rs)
                        return null;
                    break;
                }
            }
        }
    }
1157711
def fetch(self):
        
        params = values.of({})

        payload = self._version.fetch(
            'GET',
            self._uri,
            params=params,
        )

        return TaskQueueInstance(
            self._version,
            payload,
            workspace_sid=self._solution['workspace_sid'],
            sid=self._solution['sid'],
        )
673102
public static <E1> ConcurrentConveyorSingleQueue<E1> concurrentConveyorSingleQueue(
            E1 submitterGoneItem, QueuedPipe<E1> queue
    ) {
        return new ConcurrentConveyorSingleQueue<E1>(submitterGoneItem, queue);
    }
1146571
public static ExecutorService build(PoolType type, ThreadFactory factory) {
        int corePoolSize, maximumPoolSize;
        int keepAliveTime = 10;
        BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();
        switch (type) {
            case Singleton:
                corePoolSize = maximumPoolSize = 1;
                break;
            case IO:
                corePoolSize = Runtime.getRuntime().availableProcessors() * 10;
                maximumPoolSize = Runtime.getRuntime().availableProcessors() * 20;
                break;
            case Calc:
                corePoolSize = maximumPoolSize = Runtime.getRuntime().availableProcessors() + 1;
                break;
            default:
                throw new IllegalArgumentException(
                    String.format("内部异常，未知线程池类型[%s]", type.toString()));
        }
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime,
            TimeUnit.SECONDS, workQueue, factory, DEFAULT_HANDLER);
    }
1149491
public static ArchTaskExecutor getInstance() {
        if (sInstance != null) {
            return sInstance;
        }
        synchronized (ArchTaskExecutor.class) {
            if (sInstance == null) {
                sInstance = new ArchTaskExecutor();
            }
        }
        return sInstance;
    }
921107
protected Queue<AsyncResourceRequest<V>> getRequestQueueForExistingKey(K key) {
        Queue<AsyncResourceRequest<V>> requestQueue = requestQueueMap.get(key);
        return requestQueue;
    }