/*
Create and manage threads
979293
public static void setNumberOfThreads(int numThreads) {
		if (numThreads < 1)
			throw new IllegalStateException("Number of threads must be a positive integer.");
		
		if (threadPool.size() > numThreads)
			throw new IllegalStateException("You cannot set a numThreads smaller than the current size of the threads pool.");
		
		if (threadPool.size() < numThreads) {
			for (int i=threadPool.size(); i<numThreads; i++) {
				threadPool.add(Executors.newSingleThreadExecutor());
			}
		}
	}
1267351
private static ThreadFactory createThreadFactory(ThreadFactory threadFactory, String threadNamePrefix,
			Boolean daemon) {
		if (threadFactory != null) {
			return threadFactory;
		}

		if (threadNamePrefix != null) {
			if (daemon != null) {
				return ThreadPoolUtil.buildThreadFactory(threadNamePrefix, daemon);
			} else {
				return ThreadPoolUtil.buildThreadFactory(threadNamePrefix);
			}
		}

		return Executors.defaultThreadFactory();
	}
971241
def concurrent_map
      threads = services.map{|s| Thread.new{ yield s } }
      threads.each(&:join)
      threads.map(&:value)
    end
1052545
public void prepare(Collection<String> urls, String userAgent) {
        List<String> safeUrls = new ArrayList<String>(urls);
        FetchThread threads[] = new FetchThread[PREPARE_THREAD_COUNT ];
        for (int i = 0; i < PREPARE_THREAD_COUNT ; i++) {
            threads[i] = new FetchThread(safeUrls, userAgent);
            threads[i].start();
        }
        for (int i = 0; i < PREPARE_THREAD_COUNT ; i++) {
            try {
                threads[i].join();
            } catch (InterruptedException e) {
            }
        }
    }
399180
private ThreadLocal<StringMap> createThreadLocalMap() {
        final PropertiesUtil managerProps = PropertiesUtil.getProperties();
        final boolean inheritable = managerProps.getBooleanProperty(INHERITABLE_MAP);
        if (inheritable) {
            return new InheritableThreadLocal<StringMap>() {
                @Override
                protected StringMap childValue(final StringMap parentValue) {
                    return parentValue != null ? createStringMap(parentValue) : null;
                }
            };
        }
        // if not inheritable, return plain ThreadLocal with null as initial value
        return new ThreadLocal<>();
    }
1197297
function(threadId, callback) {
                var uploadQ = [];
                for (var i = 0; i < chatUploadQueue.length; i++) {
                    if (chatUploadQueue[i].threadId == threadId) {
                        uploadQ.push(chatUploadQueue[i]);
                    }
                }

                callback && callback(chatUploadQueue);
            }
1157436
def create_thread(daemon, callback, *callbackParams):
    
    task = Thread(target=callback, args=callbackParams)
    task.setDaemon(daemon)
    return task
943924
def init_threads(t=None, s=None):
    """"""
    global THREAD, SIGNAL
    THREAD = t or dummyThread
    SIGNAL = s or dummySignal
1088670
static ExecutorService createExecutorService(final String threads) {
        final int threadCount;
        if (threads.endsWith("C")) {
            threadCount = Integer.parseInt(threads.substring(0, threads.length() - 1))
                    * Runtime.getRuntime().availableProcessors();
        } else {
            threadCount = Integer.parseInt(threads);
        }
        final ClassLoader currentThreadContextClassloader = Thread.currentThread().getContextClassLoader();
        final AtomicInteger threadIndex = new AtomicInteger(1);
        return Executors.newFixedThreadPool(
                threadCount,
                r -> {
                    final Thread thread = new Thread(r);
                    thread.setName("javassist-processor-" + threadIndex.getAndIncrement());
                    thread.setContextClassLoader(currentThreadContextClassloader);
                    return thread;
                });
    }
724011
void startThread() {

        m_reportPanel.setVisible(true);
        m_startPanel.setVisible(false);
        m_report.setVisible(false);
        CmsStaticExportThread thread = new CmsStaticExportThread(A_CmsUI.getCmsObject());
        CmsReportWidget report = new CmsReportWidget(thread);
        report.setHeight("500px");
        report.setWidth("100%");
        m_layout.addComponent(report);
        thread.start();
    }
646288
public void purgeThreadLocal() {
        // if thread local pools exist, check to see if we have one created and
        // therefore need to tell it to purge
        if (null != threadLocals) {
            LocalThreadObjectPool pool = threadLocals.get();
            if (null != pool) {
                Object[] data = pool.purge();
                if (0 < data.length) {
                    mainPool.putBatch(data);
                }
            }
        }
    }
56878
public static void cleanupThreadLocals(Thread thread)
   {
      if (!OperatingSystemUtils.isJava8())
      {
         return;
      }
      try
      {
         if (thread != null)
         {
            cleanField(thread, Thread.class.getDeclaredField("threadLocals"));
            cleanField(thread, Thread.class.getDeclaredField("inheritableThreadLocals"));
         }
      }
      catch (Exception e)
      {
         log.log(Level.WARNING, "Failed to cleanup ThreadLocal instances for Thread [" + thread + "]", e);
      }
   }
1179478
public void prepare(Collection<String> surts) {
        List<String> safeSurts = new ArrayList<String>(surts);
        FetchThread threads[] = new FetchThread[PREPARE_THREAD_COUNT ];
        for (int i = 0; i < PREPARE_THREAD_COUNT ; i++) {
            threads[i] = new FetchThread(safeSurts);
            threads[i].start();
        }
        for (int i = 0; i < PREPARE_THREAD_COUNT ; i++) {
            try {
                threads[i].join();
            } catch (InterruptedException e) {
            }
        }
    }
323807
private int assignThreads(int splitIndex, int splitCount) {
    	if (threadsPerSplit > 0) {
    		return threadsPerSplit;
    	}
        if (splitCount == 1) {
            return threadCount;
        }
        if (splitCount * minThreads > threadCount) {
            return minThreads;
        }
        if (splitIndex % threadCount < threadCount % splitCount) {
            return threadCount / splitCount + 1;
        } else {
            return threadCount / splitCount;
        }
    }
1368792
@Override
    public I_CmsReportThread initializeThread() {

        List resources = new ArrayList();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamResources())) {
            resources = CmsStringUtil.splitAsList(getParamResources(), ",");
        }
        resources = CmsFileUtil.removeRedundancies(resources);

        CmsRemovePubLocksThread thread = new CmsRemovePubLocksThread(getCms(), resources);
        return thread;
    }
101973
@Override
  public void onThreadBegin()
  {
    _threadCount.incrementAndGet();
    
    int startCount = _startingCount.decrementAndGet();

    if (startCount < 0) {
      _startingCount.set(0);
      
      new IllegalStateException().printStackTrace();
    }

    _createCountTotal.incrementAndGet();
    
    update();
  }
1287785
private void manageTasks() {
        setHostAddress();
        while (!m_bShutdown) {
            checkAllTasks();
            checkForDeadTasks();
            try {
                Thread.sleep(SLEEP_TIME_MILLIS);
            } catch (InterruptedException e) {
            }
        }
        m_executor.shutdown();
    }