exceptions that happen in worker threads simply cause that thread
 to die and another to be spawned in its place.
328292
def serve
      @server_transport.listen

      begin
        loop do
          @thread_q.push(:token)
          Thread.new do
            begin
              loop do
                client = @server_transport.accept
                trans = @transport_factory.get_transport(client)
                prot = @protocol_factory.get_protocol(trans)
                begin
                  loop do
                    @processor.process(prot, prot)
                  end
                rescue Thrift::TransportException, Thrift::ProtocolException => e
                ensure
                  trans.close
                end
              end
            rescue => e
              @exception_q.push(e)
            ensure
              @thread_q.pop # thread died!
            end
          end
        end
      ensure
        @server_transport.close
      end
    end
32022
protected void dispose() {
        // Terminates the server thread
        if(serverThread != null) {
            serverThread.interrupt();
            serverThread = null;
        }

        // Stops each connection and clears them
        synchronized(connections) {
            for(FTPConnection con : connections) {
                try {
                    con.stop(true);
                } catch(Exception ex) {
                    ex.printStackTrace();
                }
            }
            connections.clear();
        }
    }
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);
        }
    }
1035705
def terminate_with_threads(self, nodes=None):
        
        if not self.is_connected():
            return None

        nodes = nodes or self.nodes
        failed_kill = []

        def worker(gce, node):
            self.logger.info("Terminating node: %s", node.name)
            terminated = gce.destroy_node(node)
            if not terminated:
                failed_kill.append(node)

        threads = []
        for node in nodes:
            thread = threading.Thread(target=worker, args=(self.gce, node))
            threads.append(thread)
            thread.start()

        self.logger.info("Waiting for nodes to shut down ...")
        for thread in threads:
            thread.join()

        return failed_kill
719876
private synchronized void createExecutor() {
        if (componentConfig == null) {
            // this is a completely normal occurrence and can happen if a ThreadFactory is bound prior to
            // component activation...  the proper thing to do is to do nothing and wait for activation
            return;
        }

        if (threadPoolController != null)
            threadPoolController.deactivate();

        ThreadPoolExecutor oldPool = threadPool;

        poolName = (String) componentConfig.get("name");
        String threadGroupName = poolName + " Thread Group";

        int coreThreads = Integer.parseInt(String.valueOf(componentConfig.get("coreThreads")));
        int maxThreads = Integer.parseInt(String.valueOf(componentConfig.get("maxThreads")));

        if (maxThreads <= 0) {
            maxThreads = Integer.MAX_VALUE;
        }

        if (coreThreads < 0) {
            coreThreads = 2 * CpuInfo.getAvailableProcessors();
        }

        // Make sure coreThreads is not bigger than maxThreads, subject to MINIMUM_POOL_SIZE limit
        coreThreads = Math.max(MINIMUM_POOL_SIZE, Math.min(coreThreads, maxThreads));
        // ... and then make sure maxThreads is not smaller than coreThreads ...
        maxThreads = Math.max(coreThreads, maxThreads);

        BlockingQueue<Runnable> workQueue = new BoundedBuffer<Runnable>(java.lang.Runnable.class, 1000, 1000);

        RejectedExecutionHandler rejectedExecutionHandler = new ExpandPolicy(workQueue, this);

        threadPool = new ThreadPoolExecutor(coreThreads, maxThreads, 0, TimeUnit.MILLISECONDS, workQueue, threadFactory != null ? threadFactory : new ThreadFactoryImpl(poolName, threadGroupName), rejectedExecutionHandler);

        threadPoolController = new ThreadPoolController(this, threadPool);

        if (oldPool != null) {
            softShutdown(oldPool);
        }
    }
335207
def thread_exception(self, raised_exception):
		
		print('Thread execution was stopped by the exception. Exception: %s' % str(raised_exception))
		print('Traceback:')
		print(traceback.format_exc())
798151
public final void drainerFailed(Throwable t) {
        if (t == null) {
            throw new NullPointerException("ConcurrentConveyor.drainerFailed(null)");
        }
        drainer = null;
        drainerDepartureCause = t;
    }
949123
public static void waitForDie(Thread thread) {
		boolean dead = false;
		do {
			try {
				thread.join();
				dead = true;
			} catch (InterruptedException e) {
				// ignore
			}
		} while (!dead);
	}
1167535
def send_caught_exception_stack_proceeded(self, thread):
        
        thread_id = get_thread_id(thread)
        int_cmd = InternalSendCurrExceptionTraceProceeded(thread_id)
        self.post_internal_command(int_cmd, thread_id)
        self.process_internal_commands()
377815
@Deprecated
    protected synchronized void workerDone(Worker w, boolean taskDied) {

        threads_.remove(w);

        if (taskDied) {
            --activeThreads;
            --poolSize_;
        }

        if (poolSize_ == 0 && shutdown_) {
            maximumPoolSize_ = minimumPoolSize_ = 0; // disable new threads
            notifyAll(); // notify awaitTerminationAfterShutdown
        }

        fireThreadDestroyed(poolSize_);
    }
979784
@Override
  public void close() {

    if (closed.compareAndSet(false, true) && numThreads > 0) {

      LOG.log(Level.FINEST, "Closing ThreadPoolStage {0}: begin", this.name);

      executor.shutdown();

      boolean isTerminated = false;
      try {
        isTerminated = executor.awaitTermination(SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
      } catch (final InterruptedException ex) {
        LOG.log(Level.WARNING, "Interrupted closing ThreadPoolStage " + this.name, ex);
      }

      if (!isTerminated) {
        final List<Runnable> droppedRunnables = executor.shutdownNow();
        LOG.log(Level.SEVERE,
            "Closing ThreadPoolStage {0}: Executor did not terminate in {1} ms. Dropping {2} tasks",
            new Object[] {this.name, SHUTDOWN_TIMEOUT, droppedRunnables.size()});
      }

      if (!executor.isTerminated()) {
        LOG.log(Level.SEVERE, "Closing ThreadPoolStage {0}: Executor failed to terminate.", this.name);
      }

      LOG.log(Level.FINEST, "Closing ThreadPoolStage {0}: end", this.name);
    }
  }
527823
@Override
    public void uncaughtException(Thread thread, Throwable thrown) {
        if (enabled) {
            logger.trace("Uncaught exception received.");

            EventBuilder eventBuilder = new EventBuilder()
                .withMessage(thrown.getMessage())
                .withLevel(Event.Level.FATAL)
                .withSentryInterface(new ExceptionInterface(thrown));

            try {
                Sentry.capture(eventBuilder);
            } catch (Exception e) {
                logger.error("Error sending uncaught exception to Sentry.", e);
            }
        }

        // taken from ThreadGroup#uncaughtException
        if (defaultExceptionHandler != null) {
            // call the original handler
            defaultExceptionHandler.uncaughtException(thread, thrown);
        } else if (!(thrown instanceof ThreadDeath)) {
            // CHECKSTYLE.OFF: RegexpSinglelineJava
            System.err.print("Exception in thread \"" + thread.getName() + "\" ");
            thrown.printStackTrace(System.err);
            // CHECKSTYLE.ON: RegexpSinglelineJava
        }
    }
1054303
public void notifyTaskFailed(TaskExecutor executor, Throwable exception) {
		synchronized (listeners) {
			int size = listeners.size();
			if(size > 0){
				for (int i = 0; i < size; i++) {
					TaskListener listenerl = listeners.get(i);
					listenerl.onFailed(executor, exception);
				}
			}else{
				StaticLog.error(exception, exception.getMessage());
			}
		}
	}
918066
def cancelThread(*threads, exception=EscapeException):
    ''
    for t in threads:
        ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(t.ident), ctypes.py_object(exception))
394625
private synchronized void cleanupThread ( long timeout ) throws TransportException {
        Thread t = this.thread;
        if ( t != null && Thread.currentThread() != t ) {
            this.thread = null;
            try {
                log.debug("Interrupting transport thread");
                t.interrupt();
                log.debug("Joining transport thread");
                t.join(timeout);
                log.debug("Joined transport thread");
            }
            catch ( InterruptedException e ) {
                throw new TransportException("Failed to join transport thread", e);
            }
        }
        else if ( t != null ) {
            this.thread = null;
        }
    }
1173998
private void doInterruptAllWaitingThreads() {
    	//Interrupt all the threads
    	for (int i=0; i<nThreads; i++) {
    		threads[i].interrupt();
    	}
    	
    	synchronized(lock) {
    		lock.notify();
    	}
    }
942423
def kill(self):
    """"""
    self._killed.set()
    if not self.is_alive():
      logging.debug('Cannot kill thread that is no longer running.')
      return
    if not self._is_thread_proc_running():
      logging.debug("Thread's _thread_proc function is no longer running, "
                    'will not kill; letting thread exit gracefully.')
      return
    self.async_raise(ThreadTerminationError)