List of usage examples for java.lang Thread join
public final void join() throws InterruptedException
From source file:com.serphacker.serposcope.task.google.GoogleTask.java
protected void waitForThreads() { while (true) { try {/*from w w w . j a v a2s . c o m*/ for (Thread thread : threads) { thread.join(); } return; } catch (InterruptedException ex) { interruptThreads(); } } }
From source file:com.slytechs.jnetstream.livecapture.AbstractLiveCapture.java
/** * Flags the capture closed and waits for all the workers to exit *///ww w.j av a 2s . co m public void close() throws IOException { this.openState = false; for (Thread worker : workers) { if (worker == null) { continue; } try { worker.join(); } catch (InterruptedException e) { break; } } client.getPacketQueue().clear(); }
From source file:ProgressBarDemo.java
/** * Return the value created by the <code>construct</code> method. * Returns null if either the constructing thread or the current * thread was interrupted before a value was produced. * // w w w . j av a 2s.c o m * @return the value created by the <code>construct</code> method */ public Object get() { while (true) { Thread t = threadVar.get(); if (t == null) { return getValue(); } try { t.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // propagate return null; } } }
From source file:azkaban.execapp.event.RemoteFlowWatcherTest.java
@Ignore @Test//from w ww . j ava 2 s. com public void testBasicRemoteFlowWatcher() throws Exception { MockExecutorLoader loader = new MockExecutorLoader(); EventCollectorListener eventCollector = new EventCollectorListener(); File workingDir1 = setupDirectory(); FlowRunner runner1 = createFlowRunner(workingDir1, loader, eventCollector, "exec1", 1, null, null); Thread runner1Thread = new Thread(runner1); File workingDir2 = setupDirectory(); RemoteFlowWatcher watcher = new RemoteFlowWatcher(1, loader, 100); FlowRunner runner2 = createFlowRunner(workingDir2, loader, eventCollector, "exec1", 2, watcher, 2); Thread runner2Thread = new Thread(runner2); printCurrentState("runner1 ", runner1.getExecutableFlow()); runner1Thread.start(); runner2Thread.start(); runner2Thread.join(); FileUtils.deleteDirectory(workingDir1); FileUtils.deleteDirectory(workingDir2); testPipelineLevel2(runner1.getExecutableFlow(), runner2.getExecutableFlow()); }
From source file:com.streamsets.datacollector.io.TestDataStore.java
@Test(timeout = 5000) public void testMultipleThreadAcquireReleaselock() throws Exception { final DataStore ds = new DataStore(new File(createTestDir(), "x")); Thread th1 = createThreadAcquireReleaseLock(ds); Thread th2 = createThreadAcquireReleaseLock(ds); th1.start();//from w w w .j a va 2 s.com th2.start(); th1.join(); th2.join(); }
From source file:io.github.mmichaelis.selenium.client.provider.AbstractWebDriverProviderTest.java
@Test public void quit_if_not_started_does_nothing() throws Exception { final WebDriverProvider driverProvider = new NoExceptionWebDriverProvider(defaultDriver); final Thread thread = Executors.defaultThreadFactory().newThread(new Runnable() { @Override//w w w. ja v a2 s . c o m public void run() { driverProvider.quit(); } }); thread.start(); thread.join(); verify(defaultDriver, never()).quit(); }
From source file:com.barchart.http.server.TestHttpServer.java
@Test public void testTooManyConnections() throws Exception { final Queue<Integer> status = new LinkedBlockingQueue<Integer>(); final Runnable r = new Runnable() { @Override// ww w .j a v a2s . c o m public void run() { try { final HttpResponse response = client .execute(new HttpGet("http://localhost:" + port + "/client-disconnect")); status.add(response.getStatusLine().getStatusCode()); } catch (final Exception e) { e.printStackTrace(); } } }; final Thread t1 = new Thread(r); t1.start(); final Thread t2 = new Thread(r); t2.start(); t1.join(); t2.join(); assertEquals(2, status.size()); assertTrue(status.contains(200)); assertTrue(status.contains(503)); }
From source file:com.all.messengine.impl.StubMessEngine.java
private void executeReaction(Runnable reaction) { Thread reactionThread = new Thread(reaction); reactionThread.start();//from w w w . j a v a2 s. c o m try { reactionThread.join(); } catch (InterruptedException e) { log.error(e, e); } }
From source file:com.continuuity.weave.kafka.client.KafkaTest.java
@Test public void testKafkaClient() throws Exception { String topic = "testClient"; Thread t1 = createPublishThread(kafkaClient, topic, Compression.GZIP, "GZIP Testing message", 10); Thread t2 = createPublishThread(kafkaClient, topic, Compression.NONE, "Testing message", 10); t1.start();// w ww . j av a 2 s .co m t2.start(); Thread t3 = createPublishThread(kafkaClient, topic, Compression.SNAPPY, "Snappy Testing message", 10); t2.join(); t3.start(); Iterator<FetchedMessage> consumer = kafkaClient.consume(topic, 0, 0, 1048576); int count = 0; long startTime = System.nanoTime(); while (count < 30 && consumer.hasNext() && secondsPassed(startTime, TimeUnit.NANOSECONDS) < 5) { LOG.info(Charsets.UTF_8.decode(consumer.next().getBuffer()).toString()); count++; } Assert.assertEquals(30, count); }
From source file:maker.task.compile.ReplTestPumpStreamHandler.java
/** * Stopping a pumper thread. The implementation actually waits * longer than specified in 'timeout' to detect if the timeout * was indeed exceeded. If the timeout was exceeded an IOException * is created to be thrown to the caller. * * @param thread the thread to be stopped * @param timeout the time in ms to wait to join *///from ww w. j ava 2s . co m protected void stopThread(final Thread thread, final long timeout) { if (thread != null) { try { if (timeout == 0) { thread.join(); } else { final long timeToWait = timeout + STOP_TIMEOUT_ADDITION; final long startTime = System.currentTimeMillis(); thread.join(timeToWait); if (!(System.currentTimeMillis() < startTime + timeToWait)) { final String msg = "The stop timeout of " + timeout + " ms was exceeded"; caught = new ExecuteException(msg, Executor.INVALID_EXITVALUE); } } } catch (final InterruptedException e) { thread.interrupt(); } } }