java.lang.Thread.suspend()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中java.lang.Thread.suspend()方法的一些代码示例,展示了Thread.suspend()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.suspend()方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:suspend

Thread.suspend介绍

[英]Suspends this thread.

First, the checkAccess method of this thread is called with no arguments. This may result in throwing a SecurityException(in the current thread).

If the thread is alive, it is suspended and makes no further progress unless and until it is resumed.
[中]挂起此线程。
首先,调用此线程的checkAccess方法时不带任何参数。这可能会导致抛出SecurityException(在当前线程中)。
如果线程处于活动状态,则它将被挂起,并且在恢复之前不会再继续进行。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * 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();
  }
}

代码示例来源:origin: robovm/robovm

@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;
}

代码示例来源:origin: apache/pulsar

public void run() {
    try {
      t.suspend();
      l.countDown();
      Thread.sleep(seconds * 1000);
      t.resume();
    } catch (Exception e) {
      LOG.error("Error suspending thread", e);
    }
  }
};

代码示例来源:origin: apache/ignite

/**
 * @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();
  }
}

代码示例来源:origin: scouter-project/scouter

ctx.thread.resume();
} else if ("suspend".equalsIgnoreCase(action)) {
  ctx.thread.suspend();

代码示例来源:origin: scouter-project/scouter

ctx.thread.resume();
} else if ("suspend".equalsIgnoreCase(action)) {
  ctx.thread.suspend();

代码示例来源:origin: apache/ignite

thread.suspend();
blockedAnything = true;

代码示例来源:origin: loveincode/Java-Multi-thread-Programming

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;
}

代码示例来源:origin: loveincode/Java-Multi-thread-Programming

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");
  }
}

代码示例来源:origin: org.gephi/desktop-branding

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();
      }
    }
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * 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();
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * 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();
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * 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();
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * 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();
  }
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * 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();
  }
}

代码示例来源:origin: zycgit/hasor

@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();
      }
    }
  }
};

代码示例来源:origin: stackoverflow.com

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");
  }
}

代码示例来源:origin: com.jtransc/jtransc-rt

@Deprecated
@SuppressWarnings("deprecation")
public final void suspend() {
  for (Thread thread : getThreadsCopy()) thread.suspend();
  for (ThreadGroup group : getChildrenCopy()) group.suspend();
}

代码示例来源:origin: javapathfinder/jpf-core

@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();
 }
}

代码示例来源:origin: javapathfinder/jpf-core

@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");
  }
 }
}

相关文章