Example usage for org.springframework.util StopWatch StopWatch

List of usage examples for org.springframework.util StopWatch StopWatch

Introduction

In this page you can find the example usage for org.springframework.util StopWatch StopWatch.

Prototype

public StopWatch() 

Source Link

Document

Construct a new StopWatch .

Usage

From source file:kymr.github.io.future.LoadTest.java

public static void main(String[] args) throws InterruptedException {
    ExecutorService es = Executors.newFixedThreadPool(100);

    RestTemplate rt = new RestTemplate();
    String url = "http://localhost:8080/dr";

    StopWatch main = new StopWatch();
    main.start();//from  w ww . j  a  va 2 s  .  co  m

    for (int i = 0; i < 100; i++) {
        es.execute(() -> {
            int idx = counter.addAndGet(1);
            log.info("Thread {}", idx);

            StopWatch sw = new StopWatch();
            sw.start();

            rt.getForObject(url, String.class);

            sw.stop();
            log.info("Elapsed: {} -> {}", idx, sw.getTotalTimeSeconds());
        });
    }

    es.shutdown();
    es.awaitTermination(100, TimeUnit.SECONDS);

    main.stop();
    log.info("Total: {}", main.getTotalTimeSeconds());
}

From source file:test.node.TestNodeWorker.java

public static void main(String[] args) {

    try {/*from  w w w.j  av a  2s.  c  om*/

        log.info("GridNode Starting...");
        StopWatch sw = new StopWatch();
        sw.start();

        // Start Grid Node
        GridNode node = Grid.startGridNode();

        sw.stop();
        log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

        log.info("GridNode ID : " + node.getId());

        log.debug("Press any key to unregister GridNode and terminate");
        System.in.read();
        node.getNodeRegistrationService().unregister();

        log.info("Unregistered, Terminating...");
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:test.node.TestUnboudedJobRunner.java

public static void main(String[] args) {
    // Test Job//w  w w . ja v  a2 s  . c o  m
    TestUnboundedJob testJob = new TestUnboundedJob();

    try {

        log.info("GridNode Starting...");
        StopWatch sw = new StopWatch();
        sw.start();

        GridNode node = Grid.startGridNode();

        log.info("GridNode ID : " + node.getId());

        sw.stop();

        log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

        // Submit Job
        log.debug("Submitting Job");

        sw.start();

        GridJobFuture future = node.getJobSubmissionService().submitJob(testJob, new ResultCallback() {

            public void onResult(Serializable result) {
                System.err.println(result);
            }

        });

        while (!future.isJobFinished()) {
            Thread.sleep(1000);
        }

        sw.stop();
        log.info("GridJob Finished. Duration " + sw.getLastTaskTimeMillis() + " ms");

        log.debug("Press any key to unregister GridNode and terminate");
        System.in.read();
        node.getNodeRegistrationService().unregister();

        log.info("Unregistered, Terminating...");
        System.exit(0);

    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:test.node.TestNodeRunner.java

public static void main(String[] args) {

    // Test Job//from  ww w  .j  av a 2 s .  c o  m
    TestJob testJob = new TestJob();

    try {

        log.info("GridNode Starting...");
        StopWatch sw = new StopWatch();
        sw.start();

        GridNode node = Grid.startGridNode();

        log.info("GridNode ID : " + node.getId());

        sw.stop();

        log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

        // Submit Job
        log.debug("Submitting Job");

        sw.start();

        GridJobFuture future = node.getJobSubmissionService().submitJob(testJob, new ResultCallback() {

            public void onResult(Serializable result) {
                System.err.println(result);
            }

        });
        try {
            log.info("Job Result : " + future.getResult());
        } catch (RemoteInvocationFailureException e) {
            e.getCause().printStackTrace();
        }

        sw.stop();
        log.info("GridJob Finished. Duration " + sw.getLastTaskTimeMillis() + " ms");

        log.debug("Press any key to unregister GridNode and terminate");
        System.in.read();
        node.getNodeRegistrationService().unregister();

        log.info("Unregistered, Terminating...");
        System.exit(0);

    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:test.node.TestNodeNARRunner.java

public static void main(String[] args) {
    try {//from   w ww.  j a  v  a 2 s .com

        log.info("GridNode Starting...");
        StopWatch sw = new StopWatch();
        sw.start();

        GridNode node = Grid.startGridNode();

        log.info("GridNode ID : " + node.getId());

        sw.stop();

        log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

        // Submit Job
        log.debug("Reading NAR");

        sw.start();

        GridArchive archive;
        archive = GridArchive.fromFile(new File("simpletestjob.nar"));

        log.debug("Submitting NAR");

        GridJobFuture future = (GridJobFuture) node.getJobSubmissionService().submitArchive(archive).values()
                .toArray()[0];

        try {
            log.info("RESULT : " + future.getResult());
        } catch (RemoteInvocationFailureException e) {
            e.getCause().printStackTrace();
        }

        sw.stop();
        log.info("GridJob Finished. Duration " + sw.getLastTaskTimeMillis() + " ms");

        log.debug("Press any key to unregister GridNode and terminate");
        System.in.read();
        node.getNodeRegistrationService().unregister();

        log.info("Unregistered, Terminating...");
        System.exit(0);

    } catch (GridArchiveException e) {
        log.fatal("GridArchiveException", e);
    } catch (GridExecutionException e) {
        log.fatal("Execution Failed", e);
    } catch (IOException e) {
        log.error("IOException", e);
    }

}

From source file:example.springdata.redis.sentinel.RedisSentinelApplication.java

public static void main(String[] args) throws Exception {

    ApplicationContext context = SpringApplication.run(RedisSentinelApplication.class, args);

    StringRedisTemplate template = context.getBean(StringRedisTemplate.class);
    template.opsForValue().set("loop-forever", "0");

    StopWatch stopWatch = new StopWatch();

    while (true) {

        try {//from w w w .  j a v  a  2  s .co  m

            String value = "IT:= " + template.opsForValue().increment("loop-forever", 1);
            printBackFromErrorStateInfoIfStopWatchIsRunning(stopWatch);
            System.out.println(value);

        } catch (RuntimeException e) {

            System.err.println(e.getCause().getMessage());
            startStopWatchIfNotRunning(stopWatch);
        }

        Thread.sleep(1000);
    }
}

From source file:example.springdata.redis.sentinel.RedisSentinelApplicationConfig.java

public static void main(String[] args) throws Exception {

    ApplicationContext context = SpringApplication.run(RedisSentinelApplicationConfig.class, args);

    RedisConnectionFactory factory = context.getBean(RedisConnectionFactory.class);

    StringRedisTemplate template = new StringRedisTemplate();
    template.setConnectionFactory(factory);
    template.afterPropertiesSet();/*from  w w w  . j a v a2s  . c om*/

    template.opsForValue().set("loop-forever", "0");

    StopWatch stopWatch = new StopWatch();

    while (true) {

        try {
            String value = "IT:= " + template.opsForValue().increment("loop-forever", 1);
            printBackFromErrorStateInfoIfStopWatchIsRunning(stopWatch);
            System.out.println(value);
        } catch (RuntimeException e) {
            System.err.println(e.getCause().getMessage());
            startStopWatchIfNotRunning(stopWatch);
        }

        Thread.sleep(1000);
    }
}

From source file:test.mandelbrot.SequentialMandelbrotApp.java

public static void main(String[] args) {

    log.info("Starting Sequential Mandelbrot Application");
    // Create App Instance
    SequentialMandelbrotApp app = new SequentialMandelbrotApp();

    app.requestFocus();//ww w.j a va  2  s  .  co m

    StopWatch sw = new StopWatch();
    log.info("Starting Computation...");
    sw.start();

    // Start Rendering
    app.startRendering();

    sw.stop();

    log.info("Computation Complete... " + sw.getLastTaskTimeMillis() + "ms");
    //System.exit(0);

}

From source file:test.mandelbrot.MandelbrotApp.java

public static void main(String[] args) {

    try {// w w  w . jav  a  2 s  . c o  m

        log.info("GridNode Starting...");
        StopWatch sw = new StopWatch();
        sw.start();

        GridNode node = Grid.startLightGridNode();

        log.info("GridNode ID : " + node.getId());

        sw.stop();

        log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

        // Create App Instance
        final MandelbrotApp app = new MandelbrotApp(node);

        app.requestFocus();

        // Create Mandelbrot Job
        MandelbrotJob mandelbrotJob = new MandelbrotJob(app.getWidth(), app.getHeight());

        // Start Job Submission
        sw.start();

        GridJobFuture future = node.getJobSubmissionService().submitJob(mandelbrotJob, new ResultCallback() {

            public void onResult(Serializable result) {

                MandelbrotResult mResult = (MandelbrotResult) result;
                app.displayResult(mResult);
                app.setProgress(app.getProgress() + mResult.getLines());
            }

        });

        app.setFuture(future);
        // Block till job finishes
        future.getResult();
        app.setDone(true);

        sw.stop();

        log.info("GridJob Finished. Duration " + sw.getLastTaskTimeMillis() + " ms");

        log.debug("Press any key to unregister GridNode and terminate");
        System.in.read();
        node.getNodeRegistrationService().unregister();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:edu.isistan.carcha.CarchaPipeline.java

/**
 * The main method./* ww  w  .  j a va2 s.c o m*/
 *
 * @param args the arguments
 * @throws Exception the exception
 */
public static void main(String[] args) throws Exception {
    String inputDirectory = args[0];
    String output = args[1];

    CarchaPipeline carcha = new CarchaPipeline();
    StopWatch sw = new StopWatch();
    sw.start("executeStanfordAnnotators");
    if (args.length > 2 && args[2].equals("write")) {
        logger.info("Write Design Decision to file");
        carcha.writeAnnotations(inputDirectory, output);
    } else if (args.length > 2 && args[2].equals("sentence"))
        carcha.writeSentences(inputDirectory, output);
    else if (args.length > 2 && args[2].equals("sentence-annotator"))
        carcha.executeSentenceAnnotator(inputDirectory, output);
    else
        carcha.executeUIMAAnnotator(inputDirectory, output);
    sw.stop();
    logger.info(sw.prettyPrint());
}