Example usage for java.lang Thread isAlive

List of usage examples for java.lang Thread isAlive

Introduction

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

Prototype

public final native boolean isAlive();

Source Link

Document

Tests if this thread is alive.

Usage

From source file:com.baidu.asynchttpclient.AsyncHttpResponseHandler.java

protected void sendMessage(Message msg) {
    if (handler != null) {
        Thread thread = handler.getLooper().getThread();
        if (thread.isAlive() && !thread.isInterrupted()) {
            handler.sendMessage(msg);// w w w.  j a  v  a  2 s.c  o m
        }
    } else {
        handleMessage(msg);
    }
}

From source file:ffx.algorithms.SimulatedAnnealing.java

public void annealToTargetValues(double[] targetTemperatures, int mdSteps, double timeStep) {

    targetTemperaturesPresent = true;//from w ww.j  a v a 2  s  . com
    this.targetTemperatures = targetTemperatures;

    if (mdSteps <= 0) {
        mdSteps = 100;
    }
    this.mdSteps = mdSteps;

    if (timeStep <= 0) {
        timeStep = 1.0;
    }
    this.timeStep = timeStep;

    Thread annealingThread = new Thread(this);
    annealingThread.start();
    synchronized (this) {
        try {
            while (annealingThread.isAlive()) {
                wait(100);
            }
        } catch (Exception e) {
            String message = "Simualted annealing interrupted.";
            logger.log(Level.WARNING, message, e);
        }
    }
}

From source file:com.alibaba.wasp.LocalWaspCluster.java

/**
 * Wait for Mini Wasp Cluster to shut down. Presumes you've already called
 * {@link #shutdown()}./* w  w w .j  a v  a2  s  .com*/
 */
public void join() {
    if (this.fserverThreads != null) {
        for (Thread t : this.fserverThreads) {
            if (t.isAlive()) {
                try {
                    Threads.threadDumpingIsAlive(t);
                } catch (InterruptedException e) {
                    LOG.debug("Interrupted", e);
                }
            }
        }
    }
    if (this.masterThreads != null) {
        for (Thread t : this.masterThreads) {
            if (t.isAlive()) {
                try {
                    Threads.threadDumpingIsAlive(t);
                } catch (InterruptedException e) {
                    LOG.debug("Interrupted", e);
                }
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.catalog.TestCatalogTracker.java

private void startWaitAliveThenWaitItLives(final Thread t, final int ms) {
    t.start();/*from   w  w  w .jav  a  2 s.  c o  m*/
    while (!t.isAlive()) {
        // Wait
    }
    // Wait one second.
    Threads.sleep(ms);
    Assert.assertTrue("Assert " + t.getName() + " still waiting", t.isAlive());
}

From source file:org.apache.hadoop.hbase.LocalHBaseCluster.java

/**
 * Wait for Mini HBase Cluster to shut down.
 * Presumes you've already called {@link #shutdown()}.
 *//*from  w  w w.  j  ava2 s  . c om*/
public void join() {
    if (this.regionThreads != null) {
        for (Thread t : this.regionThreads) {
            if (t.isAlive()) {
                try {
                    Threads.threadDumpingIsAlive(t);
                } catch (InterruptedException e) {
                    LOG.debug("Interrupted", e);
                }
            }
        }
    }
    if (this.masterThreads != null) {
        for (Thread t : this.masterThreads) {
            if (t.isAlive()) {
                try {
                    Threads.threadDumpingIsAlive(t);
                } catch (InterruptedException e) {
                    LOG.debug("Interrupted", e);
                }
            }
        }
    }
}

From source file:ffx.algorithms.SimulatedAnnealing.java

/**
 * <p>/*  w w  w  . j ava 2 s  . c om*/
 * anneal</p>
 *
 * @param highTemperature a double.
 * @param lowTemperature a double.
 * @param annealingSteps a int.
 * @param mdSteps a int.
 * @param timeStep a double
 */
public void anneal(double highTemperature, double lowTemperature, int annealingSteps, int mdSteps,
        double timeStep) {

    /**
     * Return if already running; Could happen if two threads call dynamic
     * on the same SimulatedAnnealing instance.
     */
    if (!done) {
        logger.warning(" Programming error - a thread invoked anneal when it was already running.");
        return;
    }
    done = false;
    logger.info(" Simulated annealing starting up");

    if (annealingSteps <= 0) {
        annealingSteps = 1;
    }
    this.annealingSteps = annealingSteps;
    if (highTemperature < 0) {
        highTemperature = 400.0;
    }
    this.highTemperature = highTemperature;
    if (annealingSteps == 1) {
        lowTemperature = highTemperature;
    } else if (lowTemperature < 0.0 || lowTemperature > highTemperature) {
        lowTemperature = 100;
    }
    this.lowTemperature = lowTemperature;

    if (mdSteps <= 0) {
        mdSteps = 100;
    }
    this.mdSteps = mdSteps;

    if (timeStep <= 0) {
        timeStep = 1.0;
    }
    this.timeStep = timeStep;

    logger.info(String.format(" Initial temperature:    %8.3f (Kelvin)", highTemperature));
    logger.info(String.format(" Final temperature:      %8.3f (Kelvin)", lowTemperature));
    logger.info(String.format(" Annealing steps:        %8d", annealingSteps));
    logger.info(String.format(" MD steps/temperature:   %8d", mdSteps));
    logger.info(String.format(" MD time step:           %8.3f (fs)", timeStep));

    Thread annealingThread = new Thread(this);
    annealingThread.start();
    synchronized (this) {
        try {
            while (annealingThread.isAlive()) {
                wait(100);
            }
        } catch (Exception e) {
            String message = "Simualted annealing interrupted.";
            logger.log(Level.WARNING, message, e);
        }
    }

}

From source file:org.apache.hadoop.hbase.regionserver.transactional.TestTHLogRecovery.java

private void threadDumpingJoin(final Thread t) {
    if (t == null) {
        return;//from   w w w .j a v a 2 s. c om
    }
    long startTime = EnvironmentEdgeManager.currentTimeMillis();
    while (t.isAlive()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.info("Continuing...", e);
        }
        if (EnvironmentEdgeManager.currentTimeMillis() - startTime > 60000) {
            startTime = EnvironmentEdgeManager.currentTimeMillis();
            ReflectionUtils.printThreadInfo(new PrintWriter(System.out),
                    "Automatic Stack Trace every 60 seconds waiting on " + t.getName());
        }
    }
}

From source file:edu.uci.ics.crawler4j.crawler.CrawlController.java

/**
 * Checks if is any thread working./*from ww  w. j  a v a 2  s  .c  o  m*/
 * 
 * @return true, if is any thread working
 */
private boolean isAnyThreadWorking() {
    boolean someoneIsWorking = false;
    for (int i = 0; i < threads.size(); i++) {
        Thread thread = threads.get(i);
        if (thread.isAlive() && thread.getState() == State.RUNNABLE) {
            someoneIsWorking = true;
        }
    }
    return someoneIsWorking;
}

From source file:org.archive.mapred.ARCMapRunner.java

protected void startIndexingThread(Thread thread, ARCReporter reporter) throws IOException {
    thread.setDaemon(true);/*from   w  ww  .ja v  a 2s  . c  o m*/
    thread.start();
    final long start = System.currentTimeMillis();
    try {
        for (long period = this.maxtime; thread.isAlive()
                && (period > 0); period = this.maxtime - (System.currentTimeMillis() - start)) {
            try {
                thread.join(period);
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    } finally {
        cleanup(thread, reporter);
    }
}

From source file:org.polymap.core.runtime.UIJob.java

/**
 * This cancels the job and, if this does not succeeded, it interrupts the
 * thread of the job. This gives NIO request the chance to cancel.
 *//*from   ww  w . j  av a  2s .  com*/
public boolean cancelAndInterrupt() {
    boolean result = cancel();
    if (!result) {
        Thread jobThread = UIJob.this.getThread();
        if (jobThread != null && jobThread.isAlive()) {
            jobThread.interrupt();
        }
    }
    return result;
}