/** * Suspends every thread in this group and recursively in all its * subgroups. * * @see Thread#suspend * @see #resume * * @deprecated Requires deprecated method {@link Thread#suspend()}. */ @SuppressWarnings("deprecation") @Deprecated public final void suspend() { if (suspendHelper()) { Thread.currentThread().suspend(); } }
@SuppressWarnings("deprecation") private boolean suspendHelper() { boolean suspendCurrent = false; synchronized (threadRefs) { Thread current = Thread.currentThread(); for (Thread thread : threads) { if (thread == current) { suspendCurrent = true; } else { thread.suspend(); } } } synchronized (groups) { for (ThreadGroup group : groups) { suspendCurrent |= group.suspendHelper(); } } return suspendCurrent; }
public void run() { try { t.suspend(); l.countDown(); Thread.sleep(seconds * 1000); t.resume(); } catch (Exception e) { LOG.error("Error suspending thread", e); } } };
/** * @param suspend If {@code true} suspends worker threads. */ public void pauseAll(boolean suspend) { pauseResumeOperation(true, openSockLock, writeLock); if (suspend) { for (Thread t : impl.threads()) t.suspend(); } }
ctx.thread.resume(); } else if ("suspend".equalsIgnoreCase(action)) { ctx.thread.suspend();
ctx.thread.resume(); } else if ("suspend".equalsIgnoreCase(action)) { ctx.thread.suspend();
thread.suspend(); blockedAnything = true;
public void setValue(String u, String p) { this.username = u; if (Thread.currentThread().getName().equals("a")) { System.out.println("停止a线程!"); Thread.currentThread().suspend(); } this.password = p; }
synchronized public void printString() { System.out.println("begin"); if (Thread.currentThread().getName().equals("a")) { System.out.println("a线程永远 suspend了!"); Thread.currentThread().suspend(); } System.out.println("end"); } }
private void suspendThreads() { Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); // List every thread in the group for (Thread t : threadSet) { if (t.getName().startsWith(GENERATOR_THREAD) || t.getName().startsWith(IMPORTER_THREAD) || t.getName().startsWith(EXPORTER_THREAD) || t.getName().startsWith(PROJECT_THREAD) || t.getName().startsWith(STATISTICS_THREAD) || t.getName().startsWith(PREVIEW_THREAD)) { if (t.isAlive()) { t.suspend(); } } } }
/** * Suspends every thread in this group and recursively in all its * subgroups. * * @see Thread#suspend * @see #resume * * @deprecated Requires deprecated method {@link Thread#suspend()}. */ @SuppressWarnings("deprecation") @Deprecated public final void suspend() { if (suspendHelper()) { Thread.currentThread().suspend(); } }
/** * Suspends every thread in this group and recursively in all its * subgroups. * * @see Thread#suspend * @see #resume * * @deprecated Requires deprecated method {@link Thread#suspend()}. */ @SuppressWarnings("deprecation") @Deprecated public final void suspend() { if (suspendHelper()) { Thread.currentThread().suspend(); } }
/** * Suspends every thread in this group and recursively in all its * subgroups. * * @see Thread#suspend * @see #resume * * @deprecated Requires deprecated method {@link Thread#suspend()}. */ @SuppressWarnings("deprecation") @Deprecated public final void suspend() { if (suspendHelper()) { Thread.currentThread().suspend(); } }
/** * Suspends every thread in this group and recursively in all its * subgroups. * * @see Thread#suspend * @see #resume * * @deprecated Requires deprecated method {@link Thread#suspend()}. */ @SuppressWarnings("deprecation") @Deprecated public final void suspend() { if (suspendHelper()) { Thread.currentThread().suspend(); } }
/** * Suspends every thread in this group and recursively in all its * subgroups. * * @see Thread#suspend * @see #resume * * @deprecated Requires deprecated method {@link Thread#suspend()}. */ @SuppressWarnings("deprecation") @Deprecated public final void suspend() { if (suspendHelper()) { Thread.currentThread().suspend(); } }
@Override public void evaluate() throws Throwable { try { /*A.启动监控线程*/ for (Thread thread : daemonThreads) { thread.start(); } invokerStatement.evaluate(); } finally { /*b.终止监控线程*/ for (Thread thread : daemonThreads) { thread.suspend(); thread.interrupt(); } } } };
public class Test implements Runnable { public void run() { synchronized(this) { // some work } } public static void main(String args[]) throws Exception { Test target = new Test(); Thread t = new Thread(target); t.start(); synchronized(target) { t.suspend(); } System.out.println("Hi"); } }
@Deprecated @SuppressWarnings("deprecation") public final void suspend() { for (Thread thread : getThreadsCopy()) thread.suspend(); for (ThreadGroup group : getChildrenCopy()) group.suspend(); }
@Test public void testBasicSuspendDeadlock(){ if (verifyDeadlock("+cg.threads.break_yield")) { Thread t1 = new T1(); t1.start(); while (!isRunning) { Thread.yield(); } t1.suspend(); assertTrue(t1.getState() == Thread.State.RUNNABLE); pass = true; // without resuming, T1 should not be scheduled again, despite being in a RUNNABLE state //t1.resume(); } }
@Test public void testLockholderSuspendDeadlock(){ if (verifyDeadlock("+cg.threads.break_yield")) { Thread t2 = new T2(); t2.start(); while (!isRunning) { Thread.yield(); } System.out.println("main suspending t2"); t2.suspend(); // now t2 should hold and never give up its lock synchronized (t2){ fail("main should never get here"); } } }