Example usage for java.lang Thread join

List of usage examples for java.lang Thread join

Introduction

In this page you can find the example usage for java.lang Thread join.

Prototype

public final void join() throws InterruptedException 

Source Link

Document

Waits for this thread to die.

Usage

From source file:Main.java

public ThreadGroupDemo() {
    try {/*from w w w. j a v  a 2s  .c  o  m*/
        ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

        ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

        Thread t1 = new Thread(pGroup, this);
        System.out.println("Starting " + t1.getName());
        t1.start();

        Thread t2 = new Thread(cGroup, this);
        System.out.println("Starting " + t2.getName());
        t2.start();

        t1.join();
        t2.join();

        if (!cGroup.isDestroyed()) {
            cGroup.destroy();
        } else {
            System.out.println(cGroup.getName() + " destroyed");
        }

        // parent group destroyed
        if (!pGroup.isDestroyed()) {
            pGroup.destroy();
        } else {
            System.out.println(pGroup.getName() + " destroyed");
        }

    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}

From source file:com.amazonaws.cognito.DeveloperAuthenticationProvider.java

@Override
public String getIdentityId() {
    identityId = CognitoSyncClientManager.credentialsProvider.getCachedIdentityId();

    if (identityId == null) {

        if (getProviderName() != null && !this.loginsMap.isEmpty()
                && this.loginsMap.containsKey(getProviderName())) {

            Log.e("Dev Auth", "Identity id is null");

            Foo foo = new Foo();
            Thread t = new Thread(foo);
            t.start();//from  www.jav  a  2s  . c o  m
            try {
                t.join();
            } catch (Exception e) {
                e.printStackTrace();
            }
            // update(Global.myAccountInfo.getIdentityId(), Global.myAccountInfo.getToken());

            return foo.getIdentityId();
        } else {
            return super.getIdentityId();
        }

    } else {
        Log.e("Dev Auth", "Identity id is available");
        return identityId;
    }
}

From source file:org.apache.solr.handler.TestSolrConfigHandlerConcurrent.java

@Test
public void test() throws Exception {
    Map editable_prop_map = (Map) Utils.fromJSONResource("EditableSolrConfigAttributes.json");
    Map caches = (Map) editable_prop_map.get("query");

    setupHarnesses();//from w w  w  .  j  a v a 2 s.c o m
    List<Thread> threads = new ArrayList<>(caches.size());
    final List<List> collectErrors = new ArrayList<>();

    for (Object o : caches.entrySet()) {
        final Map.Entry e = (Map.Entry) o;
        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    ArrayList errs = new ArrayList();
                    collectErrors.add(errs);
                    invokeBulkCall((String) e.getKey(), errs, (Map) e.getValue());
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        };
        threads.add(t);
        t.start();
    }

    for (Thread thread : threads)
        thread.join();

    boolean success = true;

    for (List e : collectErrors) {
        if (!e.isEmpty()) {
            success = false;
            log.error(e.toString());
        }

    }

    assertTrue(collectErrors.toString(), success);

}

From source file:com.espertech.esper.regression.nwtable.TestTableMTGroupedFAFReadFAFWriteChain.java

private void tryMT(int numInserted) throws Exception {

    String epl = "create table MyTable (key int primary key, p0 int);";
    epService.getEPAdministrator().getDeploymentAdmin().parseDeploy(epl);

    List<BaseRunnable> runnables = new ArrayList<BaseRunnable>();

    LinkedBlockingDeque<Integer> insertOutQ = new LinkedBlockingDeque<Integer>();
    InsertRunnable insert = new InsertRunnable(epService, numInserted, insertOutQ);
    runnables.add(insert);/*from ww w  .j a  va2s.  c o  m*/

    LinkedBlockingDeque<Integer> selectOutQ = new LinkedBlockingDeque<Integer>();
    SelectRunnable select = new SelectRunnable(epService, insertOutQ, selectOutQ);
    runnables.add(select);

    LinkedBlockingDeque<Integer> updateOutQ = new LinkedBlockingDeque<Integer>();
    UpdateRunnable update = new UpdateRunnable(epService, selectOutQ, updateOutQ);
    runnables.add(update);

    LinkedBlockingDeque<Integer> deleteOutQ = new LinkedBlockingDeque<Integer>();
    DeleteRunnable delete = new DeleteRunnable(epService, updateOutQ, deleteOutQ);
    runnables.add(delete);

    // start
    Thread[] threads = new Thread[runnables.size()];
    for (int i = 0; i < runnables.size(); i++) {
        threads[i] = new Thread(runnables.get(i));
        threads[i].start();
    }

    // join
    for (Thread t : threads) {
        t.join();
    }

    // assert
    for (BaseRunnable runnable : runnables) {
        assertNull(runnable.getException());
        assertEquals("failed for " + runnable, numInserted + 1, runnable.getNumberOfOperations()); // account for -1 indicator
    }
}

From source file:fitnesse.FitNesseExpediterTest.java

@Test
public void testIncompleteRequestsTimeOut() throws Exception {
    final FitNesseExpediter sender = preparePipedFitNesseExpediter();

    Thread senderThread = makeSendingThread(sender);
    senderThread.start();/*from w w  w . ja v a2 s  .c o m*/
    Thread parseResponseThread = makeParsingThread();
    parseResponseThread.start();
    Thread.sleep(300);

    parseResponseThread.join();

    assertEquals(408, response.getStatus());
}

From source file:test.integ.be.fedict.hsm.model.ConcurrencyTest.java

@Test
public void testPKCS11Concurrency() throws Exception {
    LOG.debug("PKCS#11 concurrency test");
    LOG.debug("base url: " + this.baseURL);

    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(this.baseURL + "rest/test/init");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpClient.execute(httpGet, responseHandler);
    LOG.debug("response: " + responseBody);

    Thread eTokenThread = new Thread(new ETokenTest());
    Thread beIdThread = new Thread(new BeIDTest());

    eTokenThread.start();/*w  ww.ja  v a 2  s .  c  om*/
    beIdThread.start();

    eTokenThread.join();
    beIdThread.join();
}

From source file:fr.aliasource.index.core.SearchDirector.java

/**
 * Waits for crawl threads completion & prevents new additions to the index
 *///  w w  w  . j av  a  2 s  . co m
public void stopCrawlers() {
    stopped = true;
    if (logger.isInfoEnabled()) {
        logger.info("Waiting for running crawlers completion...");
    }
    List<Thread> toStop = new ArrayList<Thread>(runningCrawlers.size());
    synchronized (runningCrawlers) {
        toStop.addAll(runningCrawlers.values());
    }

    for (Thread t : toStop) {
        logger.info("trying to stop " + t);
        try {
            t.join();
            logger.info("thread " + t + " died cleanly.");
        } catch (InterruptedException e) {
            logger.warn("interrupted exception on crawler completion");
        }
    }

    if (logger.isInfoEnabled()) {
        logger.info("Crawlers ended.");
    }
}

From source file:ai.grakn.engine.backgroundtasks.distributed.ClusterManager.java

/**
 * When you take over leadership start a new Scheduler instance and wait for it to complete.
 * @throws Exception// w w w .jav a  2s  . c  o  m
 */
public void takeLeadership(CuratorFramework client) throws Exception {
    registerFailover(client);

    // Call close() in case of exceptions during open()
    scheduler = new Scheduler();
    scheduler.open();

    LOG.info(engineID + " has taken over the scheduler.");
    Thread schedulerThread = new Thread(scheduler);
    schedulerThread.setDaemon(true);
    schedulerThread.start();
    leaderInitLatch.countDown();
    schedulerThread.join();
}

From source file:es.uma.lcc.tasks.PicturesViewTask.java

private void handleAuthenticationError() {
    Thread t = new CookieRefresherThread(AccountManager.get(mMainActivity), mMainActivity);
    t.start();//from  w  w  w. j a  v a 2 s . co  m
    try {
        t.join();
        (new PicturesViewTask(mMainActivity, false)).execute();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:es.uma.lcc.tasks.PictureDetailsTask.java

private void handleAuthenticationError() {
    Thread t = new CookieRefresherThread(AccountManager.get(mMainActivity), mMainActivity);
    t.start();/* w w  w .  ja va  2  s. com*/
    try {
        t.join();
        (new PictureDetailsTask(mMainActivity, mPicId, false)).execute();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}