List of usage examples for java.lang Thread suspend
@Deprecated(since = "1.2") public final void suspend()
From source file:ca.uviccscu.lp.server.main.ShutdownListener.java
@Deprecated public void threadCleanup(File f) { while (!deleteFolder(f, false, 0, 0)) { l.error("Trying to stop more threads, list:"); //List remaining threads ThreadGroup tg2 = Thread.currentThread().getThreadGroup(); while (tg2.getParent() != null) { tg2 = tg2.getParent();//from w ww .ja va 2 s. c o m } //Object o = new Object(); //o.notifyAll(); Thread[] threads = new Thread[tg2.activeCount() + 1024]; tg2.enumerate(threads, true); //VERY BAD WAY TO STOP THREAD BUT NO CHOICE - need to release the file locks for (int i = 0; i < threads.length; i++) { Thread th = threads[i]; if (th != null) { l.trace("Have thread: " + i + " : " + th.getName()); if (th != null && th != Thread.currentThread() && (AEThread2.isOurThread(th) || isAzThread(th))) { l.trace("Suspending " + th.getName()); try { th.suspend(); l.trace("ok"); } catch (SecurityException e) { l.trace("Stop vetoed by SM", e); } } } } for (int i = 0; i < threads.length; i++) { Thread th = threads[i]; if (th != null) { l.trace("Have thread: " + i + " : " + th.getName()); if (th != null && th != Thread.currentThread() && (AEThread2.isOurThread(th) || isAzThread(th))) { l.trace("Stopping " + th.getName()); try { th.stop(); l.trace("ok"); } catch (SecurityException e) { l.trace("Stop vetoed by SM", e); } } } } } System.gc(); }
From source file:org.apache.bookkeeper.test.ZooKeeperUtil.java
public void sleepServer(final int seconds, final CountDownLatch l) throws InterruptedException, IOException { Thread[] allthreads = new Thread[Thread.activeCount()]; Thread.enumerate(allthreads); for (final Thread t : allthreads) { if (t.getName().contains("SyncThread:0")) { Thread sleeper = new Thread() { public void run() { try { t.suspend(); l.countDown();/*from w w w . ja v a2 s.c o m*/ Thread.sleep(seconds * 1000); t.resume(); } catch (Exception e) { LOG.error("Error suspending thread", e); } } }; sleeper.start(); return; } } throw new IOException("ZooKeeper thread not found"); }