Clears dead threads,
 frees thread pool for more jobs
 Exits when no more threads are left
964475
def manage_threads
      Thread.new do 
        while(@threads.size > 0)
          done = []
          @threads.each do |t|
            done << t if t[:thread_state] == "done" || !t.status
            # puts t.object_id.to_s + "--" + t.status.to_s + "--" + t.to_s
            # raise "Nil Thread State" if t[:thread_state].nil?
          end
          done.each{|d| @threads.delete(d)} # Clear dead threads
          
          # If no more jobs are left, mark done

          if done?
            @done = true
          else
            puts "Sleeping for 2"
            sleep 2 # Wait for more threads to spawn
          end

        end
      end
    end
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);
                }
            }
        }
    }
785047
def clear(self):
    """"""
    while self.current or self.idlers or self.queue or self.rpcs:
      current = self.current
      idlers = self.idlers
      queue = self.queue
      rpcs = self.rpcs
      _logging_debug('Clearing stale EventLoop instance...')
      if current:
        _logging_debug('  current = %s', current)
      if idlers:
        _logging_debug('  idlers = %s', idlers)
      if queue:
        _logging_debug('  queue = %s', queue)
      if rpcs:
        _logging_debug('  rpcs = %s', rpcs)
      self.__init__()
      current.clear()
      idlers.clear()
      queue[:] = []
      rpcs.clear()
      _logging_debug('Cleared')
517545
def cleanup(self):
        '''  '''
        self._processing_stop = True
        self._wakeup_processing_thread()
        self._processing_stopped_event.wait(3)
284622
private void dumpThreads() {

        if (LOG.isDebugEnabled()) {
            StringBuffer b = new StringBuffer(512);
            Iterator<CmsUUID> i = m_threads.keySet().iterator();
            while (i.hasNext()) {
                CmsUUID key = i.next();
                A_CmsReportThread thread = m_threads.get(key);
                b.append(thread.getName());
                b.append(" - ");
                b.append(thread.getUUID());
                b.append('\n');
            }
            LOG.debug(
                Messages.get().getBundle().key(
                    Messages.LOG_THREADSTORE_POOL_CONTENT_2,
                    new Integer(m_threads.size()),
                    b.toString()));
        }
    }
512071
public void clearMonitors() {
        if (uiThreadRunner.isOnUiThread()) {
            graph.clearMonitors();
        } else {
            uiThreadRunner.post(new Runnable() {
                @Override
                public void run() {
                    graph.clearMonitors();
                }
            });
        }
    }
1305004
def _clean(self):
        """"""
        if self._workers:
            for w in self._workers:
                if w.is_finished():
                    self._workers.remove(w)

        if self._threads:
            for t in self._threads:
                if t.isFinished():
                    self._threads.remove(t)
        else:
            self._timer.stop()
1050522
protected void cleanup() {
		int closed = 0;
		SendBuffer buffer;
		synchronized (buffers) {
			int buffersToClose = buffers.size() - maxConnections;
			if (buffersToClose < 1) {
				return;
			}
			Iterator<SendBuffer> i = buffers.values().iterator();
			while (i.hasNext()) {
				buffer = i.next();
				if (buffer.tryToClose()) {
					i.remove();
					closed++;
					if (closed >= buffersToClose) {
						return;
					}
				}
			}
		}
	}
167278
protected void handleDoomedThreads() {

        try {
            Iterator<CmsUUID> i = m_threads.keySet().iterator();
            Set<CmsUUID> doomed = new HashSet<CmsUUID>();
            // first collect all doomed Threads
            while (i.hasNext()) {
                CmsUUID key = i.next();
                A_CmsReportThread thread = m_threads.get(key);
                if (thread.isDoomed()) {
                    doomed.add(key);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_THREADSTORE_DOOMED_2,
                                thread.getName(),
                                thread.getUUID()));
                    }
                }
            }
            i = doomed.iterator();
            // no remove all doomed Threads from the Thread store
            while (i.hasNext()) {
                m_threads.remove(i.next());
            }
            if (LOG.isDebugEnabled()) {
                dumpThreads();
            }
        } catch (Throwable t) {
            // the Grim Reaper must not be stopped by any error
            LOG.error(Messages.get().getBundle().key(Messages.LOG_THREADSTORE_CHECK_THREADS_ERROR_0), t);
        }
    }
1184413
def shutdown_thread_pool(self, only_read=False):
        
        if self.enable_thread_pool and hasattr(self, 'thread_pool') and self.thread_pool is not None:
            self.thread_pool.shutdown()
            return True
        else:
            self.logger.warning('Current not have a thread pool is existent')
            return False
769159
public void manage(int workersCount)
   {
      this.workers.clear();
      
      WorkerThread worker = null;
      for (int i = 0; i <workersCount; i++)
      {
         worker = new WorkerThread(this); //TODO expensive use thread pool
         this.manage(worker);         
      }
      
   }
1125060
def clear(self):
    

    with synchronized(self.__queue):
      jobs = self.__queue.snapshot()
      self.__queue.clear()
    return jobs
773163
def close_thread_queues
      still_active = false
      @mutex.synchronize do
        @thread_name_to_queue.each_value do |queue|
          if queue.active?
            queue.close
            still_active = true
          end
        end
      end
      return still_active
    end
38013
protected void stopResetExpiredJobsThread() {
    if (resetExpiredJobThread != null) {
      try {
        resetExpiredJobThread.join();
      } catch (InterruptedException e) {
        log.warn("Interrupted while waiting for the reset expired jobs thread to terminate", e);
      }
  
      resetExpiredJobThread = null;
    }
  }
1140393
def _RemoveFromPool(self):
    
    with self.pool.lock:

      # Pool is shutting down, we can't interfere.
      if not self.pool.started:
        return False

      # Keep a minimum number of threads in the pool.
      if len(self.pool) <= self.pool.min_threads:
        return False

      # Remove us from our pool.
      self.pool._RemoveWorker(self.name)  # pylint: disable=protected-access

      return True
741219
void cleanUp() {
    if (threadStarted) {
      return;
    }

    Reference<?> reference;
    while ((reference = queue.poll()) != null) {
      /*
       * This is for the benefit of phantom references. Weak and soft
       * references will have already been cleared by this point.
       */
      reference.clear();
      try {
        ((FinalizableReference) reference).finalizeReferent();
      } catch (Throwable t) {
        logger.log(Level.SEVERE, "Error cleaning up after reference.", t);
      }
    }
  }
1369047
def stop(self):
        
        for run_event in self.run_events:
            run_event.clear()

        for thread in self.thread_pool:
            thread.join()