/** * 强行关闭所属线程 * * @param err * 传给Thread.stop方法的对象 */ @SuppressWarnings("deprecation") public void stop(Throwable err) { myThread.stop(err); }
@SuppressWarnings("deprecation") private void stopThread(Thread thread) { // I know that it is unsafe and the user has been warned thread.stop(); }
/** * Throws checked exceptions in un-checked manner. * Uses deprecated method. * @see #throwException(Throwable) */ @SuppressWarnings({"deprecation"}) public static void throwExceptionAlt(Throwable throwable) { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } Thread.currentThread().stop(throwable); }
@SuppressWarnings("deprecation") private static void killThread(Thread thread) { thread.stop(); }
/** * Cleanup; called when applet is terminated and unloaded. */ public void destroy() { if (null != m_trustedWorker) { m_trustedWorker.stop(); // m_trustedWorker.destroy(); m_trustedWorker = null; } m_styleURLOfCached = null; m_documentURLOfCached = null; }
/** * Automatically called when the HTML page containing the applet is no longer * on the screen. Stops execution of the applet thread. */ public void stop() { if (null != m_trustedWorker) { m_trustedWorker.stop(); // m_trustedWorker.destroy(); m_trustedWorker = null; } m_styleURLOfCached = null; m_documentURLOfCached = null; }
/** {@inheritDoc} */ @Override public boolean stopThreadById(long id) { Thread[] threads = Thread.getAllStackTraces().keySet().stream() .filter(t -> t.getId() == id) .toArray(Thread[]::new); if (threads.length != 1) return false; threads[0].stop(); return true; } }
Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); for(Thread t:threadArray) { if(t.getName().contains("Abandoned connection cleanup thread")) { synchronized(t) { t.stop(); //don't complain, it works } } }
/** {@inheritDoc} */ @Override public boolean stopThreadByUniqueName(String name) { Thread[] threads = Thread.getAllStackTraces().keySet().stream() .filter(t -> Objects.equals(t.getName(), name)) .toArray(Thread[]::new); if (threads.length != 1) return false; threads[0].stop(); return true; }
private void killThread(Thread thr) { if (null == thr) return; thr.interrupt(); try { Thread.sleep(killThreadSleepInMillis); } catch (InterruptedException ex) { } if (!thr.getState().equals(State.TERMINATED)) { thr.stop(); } }
/** * Requests the receiver Thread to stop and throw ThreadDeath. The Thread is * resumed if it was suspended and awakened if it was sleeping, so that it * can proceed to throw ThreadDeath. * * @deprecated Stopping a thread in this manner is unsafe and can * leave your application and the VM in an unpredictable state. */ @Deprecated public final void stop() { stop(new ThreadDeath()); }
/** * Stops every thread in this group and recursively in all its subgroups. * * @see Thread#stop() * @see Thread#stop(Throwable) * @see ThreadDeath * * @deprecated Requires deprecated method {@link Thread#stop()}. */ @SuppressWarnings("deprecation") @Deprecated public final void stop() { if (stopHelper()) { Thread.currentThread().stop(); } }
@SuppressWarnings("deprecation") private boolean stopHelper() { boolean stopCurrent = false; synchronized (threadRefs) { Thread current = Thread.currentThread(); for (Thread thread : threads) { if (thread == current) { stopCurrent = true; } else { thread.stop(); } } } synchronized (groups) { for (ThreadGroup group : groups) { stopCurrent |= group.stopHelper(); } } return stopCurrent; }
public static void close(final int port){ Thread thread = map.get(port); if(thread != null){ thread.stop(); } }
@SuppressWarnings("deprecation") @Override public T halt() { checkActive(true); thread.stop(); try { thread.join(); } catch (InterruptedException e) { // do nothing } return super.halt(); }
private void setStoppedState(String errorMessage) { mSendButton.setChecked(false); mRunning = false; try { if (mThread != null && mThread.isAlive()) { if (mSocket != null) mSocket.close(); if (mUdpSocket != null) mUdpSocket.close(); mThread.stop(); mThread = null; mRunning = false; } } catch (Exception e) { } if (errorMessage != null && !isFinishing()) new ErrorDialog(getString(R.string.error), errorMessage, this) .show(); }
/** * Finds missing try { ... } finally { joinPool(e); } */ void checkForkJoinPoolThreadLeaks() throws InterruptedException { Thread[] survivors = new Thread[5]; int count = Thread.enumerate(survivors); for (int i = 0; i < count; i++) { Thread thread = survivors[i]; String name = thread.getName(); if (name.startsWith("ForkJoinPool-")) { // give thread some time to terminate thread.join(LONG_DELAY_MS); if (!thread.isAlive()) { continue; } thread.stop(); throw new AssertionFailedError (String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n", toString(), name)); } } }
ctx.thread.interrupt(); } else if ("stop".equalsIgnoreCase(action)) { ctx.thread.stop(); } else if ("resume".equalsIgnoreCase(action)) { ctx.thread.resume();
ctx.thread.interrupt(); } else if ("stop".equalsIgnoreCase(action)) { ctx.thread.stop(); } else if ("resume".equalsIgnoreCase(action)) { ctx.thread.resume();
/** * @throws Exception Thrown if test fails. */ @Test public void testStopThreadByUniqueName() throws Exception { WorkersControlMXBean workersCtrlMXBean = new WorkersControlMXBeanImpl(null); Thread t = startTestThread(); assertTrue(workersCtrlMXBean.stopThreadByUniqueName(TEST_THREAD_NAME)); t.join(500); assertFalse(workersCtrlMXBean.stopThreadByUniqueName(TEST_THREAD_NAME)); Thread t1 = startTestThread(); Thread t2 = startTestThread(); assertFalse(workersCtrlMXBean.stopThreadByUniqueName(TEST_THREAD_NAME)); t1.stop(); t2.stop(); }