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:azkaban.execapp.event.LocalFlowWatcherTest.java

@Ignore
@Test//from w ww .ja  va 2 s. co  m
public void testLevel2DiffLocalFlowWatcher() 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();
    LocalFlowWatcher watcher = new LocalFlowWatcher(runner1);
    FlowRunner runner2 = createFlowRunner(workingDir2, loader, eventCollector, "exec1-mod", 2, watcher, 1);
    Thread runner2Thread = new Thread(runner2);

    runner1Thread.start();
    runner2Thread.start();
    runner2Thread.join();

    FileUtils.deleteDirectory(workingDir1);
    FileUtils.deleteDirectory(workingDir2);

    testPipelineLevel1(runner1.getExecutableFlow(), runner2.getExecutableFlow());
}

From source file:net.bluehornreader.service.FeedManagerService.java

/**
 * Just creates the leader elector and lets it take over
 *//* w w  w .j a  v a2 s. c om*/
@Override
public void run() {
    LOG.info("Starting LeaderElector ...");
    leaderElector = new LeaderElector(Config.getConfig().feedManagerTicksBeforeBecomingLeader,
            Config.getConfig().feedManagerTickInterval);
    Thread t = new Thread(leaderElector);
    t.setDaemon(true);
    t.setName("FeedManagerService/" + IP);
    t.start();
    try {
        t.join();
    } catch (InterruptedException e) {
        LOG.error("Exception running LeaderElector", e);
    }
    LOG.info(String.format("FeedManagerService %s exiting", IP));
}

From source file:ThreadTester.java

public void testBubbleSort(PrintStream out) throws IOException {
    Thread t1 = new BubbleSortThread(posArray);
    t1.start();//from   w w w. j a  v a  2s  . co  m

    out.println("Testing with postive numbers...");
    // Wait for the thread to complete
    try {
        t1.join();
        printArray(posArray, out);
    } catch (InterruptedException ignored) {
    }

    Thread t2 = new BubbleSortThread(negArray);
    t2.start();

    out.println("Testing with negative numbers...");
    try {
        t2.join();
        printArray(negArray, out);
    } catch (InterruptedException ignored) {
    }
}

From source file:gov.nih.nci.firebird.proxy.PoolingHandlerTest.java

@After
public void resetThreads() throws InterruptedException {
    threads.clear();//from w ww  .  ja  v  a 2 s.co m
    synchronized (BaseClient.class) {
        BaseClient.class.notifyAll();
    }
    for (Thread t : threads) {
        t.join();
    }
}

From source file:com.enonic.cms.itest.content.imports.ImportServiceImplTest_importJobThreadSafe.java

@Test
public void check_thread_safe_import_job() throws UnsupportedEncodingException, InterruptedException {
    // setup content type with needed import configuration
    String importsConfig = "";
    importsConfig += "<imports>";
    importsConfig += "<import base='/persons/person' mode='xml' name='importer'>";
    importsConfig += "  <mapping src='@id' dest='person-no'/>";
    importsConfig += "  <mapping src='name' dest='name'/>";
    importsConfig += "</import>";
    importsConfig += "</imports>";

    String changedContentTypeXml = personContentTypeXml.replace("<imports/>", importsConfig);
    updateContentType("PersonCty", changedContentTypeXml);

    String importData = "";
    importData += "<persons>";
    importData += "  <person id='1'>";
    importData += "     <name>USER-1</name>";
    importData += "  </person>";
    importData += "  <person id='2'>";
    importData += "     <name>USER-2</name>";
    importData += "  </person>";
    importData += "</persons>";

    // exercise/*from   w  w  w  .j ava2  s  .c  om*/
    ImportContentCommand command = new ImportContentCommand();
    command.importer = fixture.findUserByName("testuser");
    command.categoryToImportTo = fixture.findCategoryByName("Persons");
    command.importName = "importer";
    command.inputStream = new ByteArrayInputStream(importData.getBytes("UTF-8"));
    ImportJob job = importJobFactory.createImportJob(command);

    Thread one = new ImportSimulator(job);
    Thread two = new ImportSimulator(job);
    Thread three = new ImportSimulator(job);

    one.start();
    two.start();
    three.start();

    one.join();
    two.join();
    three.join();

    fixture.flushAndClearHibernateSession();
}

From source file:azkaban.execapp.event.RemoteFlowWatcherTest.java

@Ignore
@Test/*from   www.ja  v a2  s . c  om*/
public void testLevel1RemoteFlowWatcher() 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, 1);
    Thread runner2Thread = new Thread(runner2);

    runner1Thread.start();
    runner2Thread.start();
    runner2Thread.join();

    FileUtils.deleteDirectory(workingDir1);
    FileUtils.deleteDirectory(workingDir2);

    testPipelineLevel1(runner1.getExecutableFlow(), runner2.getExecutableFlow());
}

From source file:azkaban.execapp.event.RemoteFlowWatcherTest.java

@Ignore
@Test/*from w w  w . j a v a 2 s  . c o  m*/
public void testLevel2DiffRemoteFlowWatcher() 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-mod", 2, watcher, 1);
    Thread runner2Thread = new Thread(runner2);

    runner1Thread.start();
    runner2Thread.start();
    runner2Thread.join();

    FileUtils.deleteDirectory(workingDir1);
    FileUtils.deleteDirectory(workingDir2);

    testPipelineLevel1(runner1.getExecutableFlow(), runner2.getExecutableFlow());
}

From source file:io.wcm.maven.plugins.nodejs.mojo.Task.java

private void initLogging(final Process process) throws InterruptedException {
    final Thread infoLogThread = new NodejsOutputStreamHandler(process.getInputStream(), getLog());
    final Thread errorLogThread = new NodejsOutputStreamHandler(process.getErrorStream(), getLog());

    infoLogThread.start();/*from   w  w  w  .  j a  v  a2s .  com*/
    errorLogThread.start();
    infoLogThread.join();
    errorLogThread.join();
}

From source file:de.uni_potsdam.hpi.asg.common.io.Invoker.java

private ProcessReturn invoke(String[] cmd, List<String> params, File folder, int timeout) {
    List<String> command = new ArrayList<String>();
    command.addAll(Arrays.asList(cmd));
    command.addAll(params);/*from  w  w w. j  a v a2 s . c o m*/
    ProcessReturn retVal = new ProcessReturn(Arrays.asList(cmd), params);
    Process process = null;
    try {
        logger.debug("Exec command: " + command.toString());
        //System.out.println(timeout + ": " + command.toString());
        ProcessBuilder builder = new ProcessBuilder(command);
        builder.directory(folder);
        builder.environment(); // bugfix setting env in test-mode (why this works? i dont know..)
        process = builder.start();

        Thread timeoutThread = null;
        if (timeout > 0) {
            timeoutThread = new Thread(new Timeout(Thread.currentThread(), timeout));
            timeoutThread.setName("Timout for " + command.toString());
            timeoutThread.start();
        }
        IOStreamReader ioreader = new IOStreamReader(process);
        Thread streamThread = new Thread(ioreader);
        streamThread.setName("StreamReader for " + command.toString());
        streamThread.start();
        process.waitFor();
        streamThread.join();
        if (timeoutThread != null) {
            timeoutThread.interrupt();
        }
        String out = ioreader.getResult();
        //System.out.println(out);
        if (out == null) {
            //System.out.println("out = null");
            retVal.setStatus(Status.noio);
        }
        retVal.setCode(process.exitValue());
        retVal.setStream(out);
        retVal.setStatus(Status.ok);
    } catch (InterruptedException e) {
        process.destroy();
        retVal.setTimeout(timeout);
        retVal.setStatus(Status.timeout);
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage());
        retVal.setStatus(Status.ioexception);
    }
    return retVal;
}

From source file:com.cloudera.recordbreaker.analyzer.FSCrawler.java

/**
 * waitForCrawl() will block until the given crawl is complete.  If there
 * is an ongoing crawl that completes, it will return true.
 * If there was no ongoing crawl, it will return false.
 *///  w w  w .  j a  v  a  2 s.c  om
protected boolean waitForOngoingCrawl(URI fsURI, boolean shouldKill) {
    long fsId = analyzer.getCreateFilesystem(fsURI, false);
    if (fsId < 0) {
        return false;
    }
    synchronized (pendingCrawls) {
        final long crawlid = analyzer.getCreatePendingCrawl(fsId, false);
        if (crawlid < 0) {
            return false;
        }
        if (shouldKill) {
            synchronized (crawlStatusInfo) {
                CrawlRuntimeStatus cstatus = crawlStatusInfo.get(crawlid);
                cstatus.setShouldFinish(true);
            }
        }
        Thread pendingThread = pendingCrawls.get(crawlid);
        if (pendingThread != null) {
            try {
                pendingThread.join();
            } catch (InterruptedException iex) {
            }
        }
        return true;
    }
}