List of usage examples for java.lang Thread interrupt
public void interrupt()
From source file:xbird.engine.backend.QueryProcessor.java
public void cancel(RequestContext rc) { final Thread thread = _runningThreads.remove(rc); if (thread != null) { thread.interrupt(); try {// w w w . ja v a2 s .co m thread.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } _executors.shutdown(); }
From source file:org.doxu.g2.gwc.crawler.Crawler.java
private void runQueueProcessor(CrawlThreadFactory factory, CrawlerThreadPoolExecutor executor) { Thread producerThread = new QueueProcessorThread(session, factory, executor); producerThread.start();// w ww.jav a 2s . c o m try { crawlCompletedBarrier.await(); } catch (InterruptedException ex) { Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex); } producerThread.interrupt(); }
From source file:org.kududb.client.MiniKuduCluster.java
/** * Stops all the processes and deletes the folders used to store data and the flagfile. *//* ww w.j a v a 2 s.c o m*/ public void shutdown() { for (Iterator<Process> masterIter = masterProcesses.values().iterator(); masterIter.hasNext();) { masterIter.next().destroy(); masterIter.remove(); } for (Iterator<Process> tsIter = tserverProcesses.values().iterator(); tsIter.hasNext();) { tsIter.next().destroy(); tsIter.remove(); } for (Thread thread : PROCESS_INPUT_PRINTERS) { thread.interrupt(); } for (String path : pathsToDelete) { try { File f = new File(path); if (f.isDirectory()) { FileUtils.deleteDirectory(f); } else { f.delete(); } } catch (Exception e) { LOG.warn("Could not delete path {}", path, e); } } }
From source file:controller.servlet.AllDataDelete.java
/** * Mtodo stopThreads, permite parar los hilos en ejecucin. *//*ww w. j ava2s .co m*/ private void stopThreads() { Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); for (Thread thread : threadArray) { if (thread.getName().equals(ThreadName.TRACK_THREAD_NAME) || thread.getName().equals(ThreadName.AMENITIES_THREAD_NAME)) { thread.interrupt(); thread.stop(); } } }
From source file:com.tascape.qa.th.Utils.java
public static void waitForOutputLine(final Process process, String lineExpected, final long timeout) throws IOException { Thread t = new Thread() { @Override/*from w w w . ja v a 2s . c o m*/ public void run() { try { Thread.sleep(timeout); } catch (InterruptedException ex) { LOG.warn(ex.getMessage()); } finally { if (process != null) { process.destroy(); } } } }; t.setName(Thread.currentThread().getName() + "-" + t.hashCode()); t.setDaemon(true); t.start(); try (BufferedReader stdIn = new BufferedReader(new InputStreamReader(process.getInputStream()))) { for (String line = stdIn.readLine(); line != null;) { if (line.contains(lineExpected)) { break; } line = stdIn.readLine(); } } t.interrupt(); }
From source file:org.apache.hadoop.hbase.master.cleaner.HFileCleaner.java
/** * Stop threads for hfile deletion//from w w w .jav a2s. co m */ private void stopHFileDeleteThreads() { running = false; if (LOG.isDebugEnabled()) { LOG.debug("Stopping file delete threads"); } for (Thread thread : threads) { thread.interrupt(); } }
From source file:org.archive.crawler.framework.ToePool.java
public void cleanup() { // force all Toes waiting on queues, etc to proceed Thread[] toes = getToes();/*from w w w. ja v a 2 s . co m*/ for (Thread toe : toes) { if (toe != null) { toe.interrupt(); } } // see HER-2036 this.controller = null; }
From source file:org.openhab.binding.digiplex.internal.handler.DigiplexBridgeHandler.java
private void stopThread(@Nullable Thread thread) { if (thread != null) { thread.interrupt(); try {/*from ww w . j a va 2 s . c om*/ thread.join(1000); } catch (InterruptedException e) { } } }
From source file:com.cloud.utils.backoff.impl.ConstantTimeBackoffTest.java
@Test public void waitBeforeRetryWithInterrupt() throws InterruptedException { final ConstantTimeBackoff backoff = new ConstantTimeBackoff(); backoff.setTimeToWait(10);//from www.j a v a 2 s . co m Assert.assertTrue(backoff.getWaiters().isEmpty()); Thread waitThread = new Thread(new Runnable() { @Override public void run() { backoff.waitBeforeRetry(); } }); waitThread.start(); Thread.sleep(100); Assert.assertFalse(backoff.getWaiters().isEmpty()); waitThread.interrupt(); Thread.sleep(100); Assert.assertTrue(backoff.getWaiters().isEmpty()); }
From source file:org.apache.hadoop.net.TestSocketIOWithTimeout.java
public void testSocketIOWithTimeout() throws IOException { // first open pipe: Pipe pipe = Pipe.open(); Pipe.SourceChannel source = pipe.source(); Pipe.SinkChannel sink = pipe.sink(); try {/*from www. ja va2 s . c o m*/ InputStream in = new SocketInputStream(source, TIMEOUT); OutputStream out = new SocketOutputStream(sink, TIMEOUT); byte[] writeBytes = TEST_STRING.getBytes(); byte[] readBytes = new byte[writeBytes.length]; out.write(writeBytes); doIO(null, out); in.read(readBytes); assertTrue(Arrays.equals(writeBytes, readBytes)); doIO(in, null); /* * Verify that it handles interrupted threads properly. * Use a large timeout and expect the thread to return quickly. */ in = new SocketInputStream(source, 0); Thread thread = new Thread(new ReadRunnable(in)); thread.start(); try { Thread.sleep(1000); } catch (InterruptedException ignored) { } thread.interrupt(); try { thread.join(); } catch (InterruptedException e) { throw new IOException("Unexpected InterruptedException : " + e); } //make sure the channels are still open assertTrue(source.isOpen()); assertTrue(sink.isOpen()); out.close(); assertFalse(sink.isOpen()); // close sink and expect -1 from source.read() assertEquals(-1, in.read()); // make sure close() closes the underlying channel. in.close(); assertFalse(source.isOpen()); } finally { if (source != null) { source.close(); } if (sink != null) { sink.close(); } } }