List of usage examples for java.lang Thread join
public final void join() throws InterruptedException
From source file:io.kazuki.v0.store.keyvalue.KeyValueStoreBasicOperationsTest.java
@Test public void emptySchema() throws Exception { final Thread t = new Thread(new Runnable() { @Override/*from ww w. j a v a 2 s. c o m*/ public void run() { try { schema.createSchema("record", Record.SCHEMA); } catch (KazukiException e) { e.printStackTrace(); } } }); t.run(); t.join(); try (final KeyValueIterable<KeyValuePair<Record>> kvi = kvStore.iterators().entries("record", Record.class, SortDirection.ASCENDING)) { for (KeyValuePair<Record> kv : kvi) { System.out.println(kv.getValue().getKey() + " = " + kv.getValue().getValue()); } } }
From source file:io.github.mmichaelis.selenium.client.provider.AbstractWebDriverProviderTest.java
@Test public void reset_does_nothing_if_not_started() throws Exception { final WebDriverProvider driverProvider = new NoExceptionWebDriverProvider(defaultDriver); final Thread thread = Executors.defaultThreadFactory().newThread(new Runnable() { @Override/*from w w w . ja v a2 s . co m*/ public void run() { driverProvider.reset(); } }); thread.start(); thread.join(); errorCollector.checkSucceeds(new Callable<Object>() { @Nullable @Override public Object call() { verify(defaultDriver, never()).navigate(); return null; } }); errorCollector.checkSucceeds(new Callable<Object>() { @Nullable @Override public Object call() { verify(defaultDriver, never()).manage(); return null; } }); errorCollector.checkSucceeds(new Callable<Object>() { @Nullable @Override public Object call() { verify(defaultDriver, never()).getWindowHandle(); return null; } }); errorCollector.checkSucceeds(new Callable<Object>() { @Nullable @Override public Object call() { verify(defaultDriver, never()).getWindowHandles(); return null; } }); }
From source file:io.github.mmichaelis.selenium.client.provider.AbstractWebDriverProviderTest.java
@Test public void quit_ends_browser() throws Exception { final WebDriverProvider driverProvider = new NoExceptionWebDriverProvider(defaultDriver); final Thread thread = Executors.defaultThreadFactory().newThread(new Runnable() { @Override/* w w w . ja v a 2s .c om*/ public void run() { driverProvider.get(); driverProvider.quit(); } }); thread.start(); thread.join(); verify(defaultDriver, atLeastOnce()).quit(); }
From source file:com.amalto.core.save.AutoIncrementTest.java
public void testConcurrentInMemoryAutoIncrement() throws Exception { cleanAutoIncrement();/*from www . ja v a 2s.com*/ cleanTestAIData(); InMemoryAutoIncrementGenerator generator = initInMemoryAutoIncrementGenerator(); createData("TestAI", "<A></A>", false); // create a record to initialize auto-increment Thread thread1 = new StandaloneCreateThread(); Thread thread2 = new StandaloneCreateThread(); thread1.start(); thread2.start(); thread1.join(); thread2.join(); validateAutoIncrement(21L); assertEquals(generator.generateId("TestAI", "A", "Id"), "22"); }
From source file:uk.org.thegatekeeper.sa.booking.BookingServiceTest.java
@Test public void checkConcurrentBookingsForTheSameSeatUsingGates() throws Exception { Gate gate = gateController.stopFirstThread().inClass(PaymentService.class).beforeMethod("pay").build(); final List<Throwable> exceptions = new ArrayList<>(); final Seat seat = new Seat(4, 12); Thread fred = new Thread(new Runnable() { @Override//from w w w. j a v a2s .co m public void run() { try { bookingService.book(seat); } catch (Throwable t) { exceptions.add(t); } } }); fred.start(); gate.waitFor(2, TimeUnit.SECONDS); assertTrue(bookingService.book(seat)); gate.open(); fred.join(); assertEquals(1, exceptions.size()); assertTrue(exceptions.get(0) instanceof SeatAlreadyBookedException); }
From source file:broadwick.montecarlo.MonteCarlo.java
/** * Run the Monte Carlo simulations. Two threads (a producer and consumer) are created to asynchronously run the * simulations (the producer) and to handle the results from each simulation as they are calculated (the consumer). * The producer thread uses an execution pool to manage running each simulation and places the results on a queue * which is monitored by a consumer thread to calculate the posterior distributions for the Monte Carlo run. *///from w w w. j a v a2 s .c o m public final void run() { final ArrayBlockingQueue<MonteCarloResults> queue = new ArrayBlockingQueue<>(numSimulations + 1); //Creating Producer and Consumer Thread if (log.isTraceEnabled()) { log.trace("Creating Monte Carlo producer and consumer"); } final Thread producer = new Thread(new Producer(queue, simulation, numSimulations)); final Thread consumer = new Thread(new Consumer(queue, resultsConsumer)); producer.start(); consumer.start(); try { producer.join(); consumer.join(); } catch (Exception e) { log.error("Error joining Monte Carlo results {}", Throwables.getStackTraceAsString(e)); } }
From source file:es.uma.lcc.tasks.EncryptionUploaderTask.java
private void handleAuthenticationError() { System.out.println("retrying"); mIsFirstRun = false;//from w w w. j a v a 2 s . com Thread t = new CookieRefresherThread(AccountManager.get(mMainActivity), mMainActivity); t.start(); try { t.join(); new EncryptionUploaderTask(mSrc, mRectangles, mMainActivity, false).execute(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.buaa.cfs.conf.ReconfigurableBase.java
public void shutdownReconfigurationTask() { Thread tempThread; synchronized (reconfigLock) { shouldRun = false;/*from www. ja v a 2s. c o m*/ if (reconfigThread == null) { return; } tempThread = reconfigThread; reconfigThread = null; } try { tempThread.join(); } catch (InterruptedException e) { } }
From source file:com.barchart.netty.server.http.TestHttpServer.java
@Test public void testTooManyConnections() throws Exception { final Queue<Integer> status = new LinkedBlockingQueue<Integer>(); final Runnable r = new Runnable() { @Override// w w w.jav a 2 s. c om public void run() { try { final HttpResponse response = client .execute(new HttpGet("http://localhost:" + port + "/client-disconnect")); status.add(response.getStatusLine().getStatusCode()); EntityUtils.consume(response.getEntity()); } 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:org.openengsb.opencit.core.projectmanager.internal.SchedulingServiceImpl.java
@Override public void setupAndStartScmPoller(final Project project) { Thread thread = new Thread() { @Override/*from w w w. j a v a2 s .co m*/ public void run() { SecurityContextHolder.clearContext(); PollTask task = createPollTask(project); pollTasks.put(project.getId(), task); resumeScmPoller(project.getId()); } }; thread.start(); try { thread.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } }