Example usage for java.util.concurrent BrokenBarrierException printStackTrace

List of usage examples for java.util.concurrent BrokenBarrierException printStackTrace

Introduction

In this page you can find the example usage for java.util.concurrent BrokenBarrierException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:es.udc.gii.common.eaf.algorithm.parallel.evaluation.DistributedEvaluation.java

private void evaluationThread(EvolutionaryAlgorithm algorithm) {
    boolean resume = false;
    List<Individual> toEvaluate = new ArrayList<Individual>();
    int myRank = getTopology().getTopologyRank();

    /* While not done */
    while (!resume) {
        /* Try to get a free chunk (not evaluated individuals). */
        toEvaluate = getChunk(myRank);/*  ww  w . j  a  v  a  2  s  .  c  o  m*/
        if (toEvaluate.isEmpty()) {
            resume = true;
            break;
        }

        /* If we've got a free chunk */
        if (!toEvaluate.isEmpty()) {

            /* Notify observers what we have to evaluate. */
            notifyObservers(TO_EVALUATE, toEvaluate);

            /* Evaluate it. */
            if (isCollectStatistics()) {
                long evalTime = System.nanoTime();
                getEvaluationStrategy().evaluate(algorithm, toEvaluate, functions, constraints);
                evalTime = System.nanoTime() - evalTime;
                this.statistics.incTotalEvalsMaster(toEvaluate.size());
                this.statistics.incTotalEvalTimeMaster(evalTime);
            } else {
                getEvaluationStrategy().evaluate(algorithm, toEvaluate, functions, constraints);
            }

            /* Notify observers the evaluated individuals. */
            notifyObservers(EVALUATED, toEvaluate);

            /* Store the evaluated individuals. */
            setChunk(myRank, toEvaluate);

            /* If all individuals have been evaluated, we are done. */
            if (evaluatedIndividuals >= popSize) {
                resume = true;
                break;
            }
        }
    }

    long idleTime = System.nanoTime();
    /* Synchronize the two threads. Both have to be done before continuing. */
    if (!barrier.isBroken()) {
        try {
            barrier.await();
        } catch (BrokenBarrierException ex) {
            ex.printStackTrace();
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    idleTime = System.nanoTime() - idleTime;

    if (isCollectStatistics()) {
        this.statistics.incTotalIdleTimeMaster(idleTime);
    }
}

From source file:org.apache.hadoop.yarn.server.nodemanager.TestNodeManagerResync.java

@SuppressWarnings("unchecked")
@Test(timeout = 60000)/*from  w  w w  . ja  v a 2 s  .c o  m*/
public void testContainerResourceIncreaseIsSynchronizedWithRMResync()
        throws IOException, InterruptedException, YarnException {
    NodeManager nm = new TestNodeManager4();
    YarnConfiguration conf = createNMConfig();
    conf.setBoolean(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, true);
    nm.init(conf);
    nm.start();
    // Start a container and make sure it is in RUNNING state
    ((TestNodeManager4) nm).startContainer();
    // Simulate a container resource increase in a separate thread
    ((TestNodeManager4) nm).increaseContainersResource();
    // Simulate RM restart by sending a RESYNC event
    LOG.info("Sending out RESYNC event");
    nm.getNMDispatcher().getEventHandler().handle(new NodeManagerEvent(NodeManagerEventType.RESYNC));
    try {
        syncBarrier.await();
    } catch (BrokenBarrierException e) {
        e.printStackTrace();
    }
    Assert.assertFalse(assertionFailedInThread.get());
    nm.stop();
}