List of usage examples for java.lang Thread interrupt
public void interrupt()
From source file:org.uiautomation.ios.wkrdp.internal.DefaultMessageHandler.java
@Override public synchronized void stop() { stopped = true;/*from w w w .j a v a 2s .c om*/ for (Thread t : threads) { t.interrupt(); } }
From source file:org.apache.camel.component.zookeeper.operations.ZooKeeperOperation.java
public boolean cancel(boolean mayInterruptIfRunning) { if (mayInterruptIfRunning) { for (Thread waiting : waitingThreads) { waiting.interrupt(); }/*from w w w . jav a 2 s . c o m*/ cancelled = true; } return mayInterruptIfRunning; }
From source file:Main.java
public static String runScript(String script) { String sRet;/*w w w.j a v a 2s .c o m*/ try { final Process m_process = Runtime.getRuntime().exec(script); final StringBuilder sbread = new StringBuilder(); Thread tout = new Thread(new Runnable() { public void run() { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(m_process.getInputStream()), 8192); String ls_1; try { while ((ls_1 = bufferedReader.readLine()) != null) { sbread.append(ls_1).append("\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } } }); tout.start(); final StringBuilder sberr = new StringBuilder(); Thread terr = new Thread(new Runnable() { public void run() { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(m_process.getErrorStream()), 8192); String ls_1; try { while ((ls_1 = bufferedReader.readLine()) != null) { sberr.append(ls_1).append("\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } } }); terr.start(); m_process.waitFor(); while (tout.isAlive()) { Thread.sleep(50); } if (terr.isAlive()) terr.interrupt(); String stdout = sbread.toString(); String stderr = sberr.toString(); sRet = stdout + stderr; } catch (Exception e) { e.printStackTrace(); return null; } return sRet; }
From source file:com.cloud.utils.backoff.impl.ConstantTimeBackoff.java
@Override public boolean wakeup(String threadName) { Thread th = _asleep.get(threadName); if (th != null) { th.interrupt(); return true; }/*from ww w. ja v a 2 s.c o m*/ return false; }
From source file:watchserver.server.WatchFTPRunner.java
/** * Flag worker thread to stop gracefully. */// w w w.j ava 2 s . c om public void stopThread() { if (thread != null) { Thread runningThread = thread; thread = null; runningThread.interrupt(); } }
From source file:org.feistymeow.process.Defaults.java
/** * Stops the execution of the ProcessWatchingThread - or tries to. *//*from w w w .ja v a2s . c om*/ public void stop() { Thread goAway = myThread; myThread = null; if (null != goAway) { goAway.interrupt(); } }
From source file:view.UserInteractor.java
public void run(String... args) throws Exception { System.out.println(" ### Payment Tracker ### "); Scanner in = new Scanner(System.in); tryLoadFile(in);//from w w w .ja v a2 s . c o m tryLoadExchangeRates(); Thread viewerThread = startViewerThread(); userInputCycle(in); viewerThread.interrupt(); }
From source file:xbird.engine.backend.CommandProcessor.java
public void cancel(RequestContext rc) { Thread thread = _runningThreads.remove(rc); if (thread != null) { thread.interrupt(); try {/*from w w w . j a v a2 s.c o m*/ thread.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
From source file:net.sf.jabref.JabRefExecutorService.java
public void shutdownEverything() { this.executorService.shutdown(); for (Thread thread : startedThreads) { thread.interrupt(); }/* w w w. j a v a 2 s . co m*/ startedThreads.clear(); timer.cancel(); }
From source file:org.eclipse.ecr.core.event.tx.BulkExecutor.java
@Override protected void handleUnfinishedThread(Thread runner) { log.error("Bulk execution of event handlers is too long, exiting by killing thread"); runner.interrupt(); }