Example usage for org.apache.commons.lang.time StopWatch start

List of usage examples for org.apache.commons.lang.time StopWatch start

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch start.

Prototype

public void start() 

Source Link

Document

Start the stopwatch.

This method starts a new timing session, clearing any previous values.

Usage

From source file:org.examproject.batch.core.WorkerFacade.java

public void work() {
    LOG.debug("called.");
    try {/*ww  w .  java2s . co  m*/
        LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run a job begin.");

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

        // create the jobparameter.
        JobParameter parameter = new JobParameter(new Date());

        Map<String, JobParameter> map = new HashMap<String, JobParameter>();
        map.put("date", parameter);

        // run the job.
        jobLauncher.run(job, new JobParameters(map));

        stopWatch.stop();
        LOG.info("execute time: " + stopWatch.getTime() + " msec");

        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< run a job end.");

    } catch (Exception e) {
        LOG.fatal("fatal: " + e.getMessage());
    }
}

From source file:org.examproject.task.core.Facade.java

@Override
public void run() {
    LOG.debug("called.");

    try {/*www.ja va 2s  . co m*/
        LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> facade begin.");
        LOG.info("processing at " + new Date());

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

        // initialize the content object for this run.
        init();

        // set the param for the worker object of the list.
        List<Runnable> workerList = new CopyOnWriteArrayList<Runnable>();
        for (int i = 0; i < contentList.size(); i++) {

            // create the beans of result for the worker. 
            DynaBean result = (DynaBean) resultBeanFactory.create();

            // create the beans of state for the worker.
            DynaBean state = (DynaBean) stateBeanFactory.create();

            // create the beans of argument for the worker.
            DynaBean argument = (DynaBean) argumentBeanFactory.create();

            // build the parameter for the worker.
            state.set("result", result);
            state.set("param", getParam());
            argument.set("job", jobClosure);
            argument.set("state", state);
            argument.set("count", counter.incrementAndGet());

            // set the argument object for the worker.
            Runnable worker = (Runnable) context.getBean(workerBeanId, argument);

            // add the worker to the list.
            workerList.add(worker);
        }

        // run the all of the worker object.
        for (int i = 0; i < workerList.size(); i++) {
            executor.execute(workerList.get(i));
        }

        stopWatch.stop();

        LOG.info("execute time: " + stopWatch.getTime() + " msec");
        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade end.");

    } catch (Exception e) {
        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade error.");
        LOG.error("exception occurred. " + e.getMessage());

        // TODO: final strategy of the error!
        throw new RuntimeException(e);
    }
}

From source file:org.forgerock.openam.cts.reaper.CTSReaper.java

/**
 * Performs the query against the directory by selecting the Token IDs for all Tokens
 * that have expired. These Token IDs are then scheduled for deletion. The task will
 * not complete until all of the delete operations have returned.
 *//*  w  w w .  j a v a  2 s  . c  o  m*/
public void run() {
    // Timers for debugging
    StopWatch query = new StopWatch();
    StopWatch waiting = new StopWatch();

    // Latches will track each page of results
    List<CountDownLatch> latches = new ArrayList<CountDownLatch>();

    // Create the query against the directory
    calendar.setTimeInMillis(System.currentTimeMillis());
    Filter expired = factory.createFilter().and().beforeDate(calendar).build();
    QueryBuilder queryBuilder = factory.createInstance().withFilter(expired)
            .returnTheseAttributes(CoreTokenField.TOKEN_ID);
    QueryPageIterator iterator = new QueryPageIterator(queryBuilder, config.getCleanupPageSize());

    query.start();
    long total = 0;

    try {
        // Iterate over the result pages
        while (iterator.hasNext()) {
            Collection<Entry> entries = iterator.next();
            total += entries.size();

            // If the thread has been interrupted, exit all processing.
            if (Thread.interrupted()) {
                return;
            }

            // Latch will track the deletions of the page
            CountDownLatch latch = new CountDownLatch(entries.size());
            DeleteComplete complete = new DeleteComplete(latch);
            latches.add(latch);

            // Delete the tokens.
            try {
                tokenDeletion.deleteBatch(entries, complete);
            } catch (ErrorResultException e) {
                debug.error("Failed to get a connection, will retry later", e);
                return;
            }

            if (debug.messageEnabled()) {
                debug.message(MessageFormat
                        .format(CoreTokenConstants.DEBUG_HEADER + "Reaper: Queried {0} Tokens", total));
            }
        }

        query.stop();
        waiting.start();

        if (debug.messageEnabled()) {
            debug.message(MessageFormat.format(
                    CoreTokenConstants.DEBUG_HEADER + "Reaper: Expired Token Query Time: {0}ms",
                    query.getTime()));
        }

        // Wait stage
        for (CountDownLatch latch : latches) {
            try {
                latch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        waiting.stop();

        if (debug.messageEnabled()) {
            debug.message(MessageFormat.format(
                    CoreTokenConstants.DEBUG_HEADER + "Reaper: Worker threads Time: {0}ms", waiting.getTime()));
        }
    } finally {
        // Once all latches are complete, close the TokenDeletion
        IOUtils.closeIfNotNull(tokenDeletion);
    }
}

From source file:org.grouter.common.logging.MethodLogger.java

private Object log(ProceedingJoinPoint joinPoint) throws Throwable {
    log.info("Starting stopwatch");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    Object[] args = joinPoint.getArgs();
    // E.g. public abstract org.grouter.domain.entities.User org.grouter.domain.service.UserService.findById(java.lang.Long)
    String name = joinPoint.getSignature().toLongString();
    StringBuffer sb = new StringBuffer(name + " called with: [");
    for (int i = 0; i < args.length; i++) {
        Object o = args[i];/*from   w w w  .j a v a  2 s.c o  m*/
        sb.append(o);
        sb.append((i == args.length - 1) ? "]" : ", ");
    }
    log.info(sb);
    Object retVal = joinPoint.proceed();
    stopWatch.stop();

    log.info(" return: " + retVal + ", time: " + stopWatch.getTime());
    return retVal;
}

From source file:org.hippoecm.hst.demo.components.ExampleProfilingHstComponentAspect.java

public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    final HstResponse hstResponse = (HstResponse) pjp.getArgs()[1];
    final String compNamespace = hstResponse.getNamespace();

    Object retVal = pjp.proceed();

    stopWatch.stop();/*from  w  w  w .j a v  a  2 s .c om*/
    log.info("Example profiling for '{}': {}ms.", compNamespace, stopWatch.getTime());

    return retVal;
}

From source file:org.hydracache.concurrent.SimpleResultFutureTest.java

@Test
public void shouldGetBeAbleToTimeout() throws Exception {
    SimpleResultFuture<Object> responses = new SimpleResultFuture<Object>();

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

    results = responses.get(TIMEOUT, TimeUnit.MILLISECONDS);

    stopWatch.stop();//www.ja v a2  s.  c  om

    assertTrue("Timeout period is too short", stopWatch.getTime() > TIMEOUT);

    assertNotNull("Results should not be null", results);
    assertTrue("Results should be empty", results.isEmpty());
}

From source file:org.hydracache.concurrent.SimpleResultFutureTest.java

private void concurrentGet(final SimpleResultFuture<Object> future) {
    new Thread() {
        @Override//w  ww. j av a  2  s.co m
        public void run() {
            try {
                StopWatch stopWatch = new StopWatch();
                stopWatch.start();
                results = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
                stopWatch.stop();
                System.out.println("Took [" + stopWatch.getTime() + "]ms to get concurrently");

                assertTrue("Get took too long in a ideal case", stopWatch.getTime() < TIMEOUT);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}

From source file:org.hydracache.server.BasicIntegrationTest.java

@Test
public void testBasicOperations() throws Exception {
    StopWatch stopwatch = new StopWatch();

    stopwatch.start();

    String testKey = createTestKey();

    assertPutAndGet(testKey);//from ww w.j  a v a  2s  .  c  o m

    assertDeletion(testKey);

    stopwatch.stop();

    log.info("Took [" + stopwatch.getTime() + "]ms to perform a put and get pair + one deletion");
}

From source file:org.hydracache.server.BasicIntegrationTest.java

@Test
public void testRepetitivePutAndGet() throws Exception {
    StopWatch stopwatch = new StopWatch();

    stopwatch.start();

    int numberOfTests = 100;

    String testKey = createTestKey();

    for (int i = 0; i < numberOfTests; i++) {
        assertPutAndGet(testKey);/*  w w w  .ja v a 2 s.co m*/
    }

    assertDeletion(testKey);

    stopwatch.stop();

    log.info("Took [" + stopwatch.getTime() + "]ms to perform " + numberOfTests
            + " put and get pairs + one deletion");
}

From source file:org.hydracache.server.BasicPutAndGetIntegrationTest.java

@Test
public void testBasicPutAndGet() throws Exception {
    StopWatch stopwatch = new StopWatch();

    stopwatch.start();

    assertPutAndGet(createRandomKey());/*w w  w .j ava  2  s . c o  m*/

    stopwatch.stop();

    log.info("Took [" + stopwatch.getTime() + "]ms to perform a put and get pair");
}