Spring Framework StopWatch - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework StopWatch class.

This code example shows how to use the following methods:getTotalTimeMillis, start, stop
 
	@Test // SPR-6354
	public void destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang() { 
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", this.getClass());
		assertNotNull(context.getBean("lazyInitSchedulerWithDefaultShutdownOrder"));
		StopWatch sw = new StopWatch();
		sw.start("lazyScheduler");
		context.destroy();
		sw.stop();
		assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " + 
				sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
	} 
 
	@Test // SPR-6354
	public void destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang() { 
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", this.getClass());
		assertNotNull(context.getBean("lazyInitSchedulerWithCustomShutdownOrder"));
		StopWatch sw = new StopWatch();
		sw.start("lazyScheduler");
		context.destroy();
8
CodeRank
This code example shows how to use the following methods:shortSummary, start, stop
 
 
	@Override 
	protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { 
		String name = createInvocationTraceName(invocation); 
		StopWatch stopWatch = new StopWatch(name); 
		stopWatch.start(name); 
		try { 
			return invocation.proceed(); 
		} 
		finally { 
			stopWatch.stop(); 
			logger.trace(stopWatch.shortSummary()); 
		} 
	} 
 
} 
8
CodeRank
This code example shows how to use the following methods:getTotalTimeMillis, isRunning, start, stop
	 * @see #setExceptionMessage 
	 */ 
	@Override 
	protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { 
		String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName(); 
		StopWatch stopWatch = new StopWatch(name); 
		Object returnValue = null; 
		boolean exitThroughException = false; 
		try { 
			stopWatch.start(name); 
			writeToLog(logger, 
					replacePlaceholders(this.enterMessage, invocation, null, null, -1)); 
			returnValue = invocation.proceed(); 
			return returnValue; 
		} 
		catch (Throwable ex) { 
			if (stopWatch.isRunning()) { 
				stopWatch.stop(); 
			} 
			exitThroughException = true; 

7
CodeRank
This code example shows how to use the following methods:getLastTaskName, shortSummary, start, stop
//@Component 
public class ProfilingAspect { 
 
    @Around("methodsToBeProfiled()") 
    public Object profile(ProceedingJoinPoint pjp) throws Throwable {
        StopWatch sw = new StopWatch(getClass().getSimpleName());
        try { 
            sw.start(pjp.getSignature().getName());
            return pjp.proceed();
        } finally { 
            sw.stop();
            System.out.println(sw.getLastTaskName() + sw.shortSummary());
        } 
    } 
 
    @Pointcut("execution(public * org.axonframework.eventstore.mongo.MongoEventStore.*(..))") 
    public void methodsToBeProfiled() { 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:shortSummary, start, stop
 
	public class PerformanceMonitorInterceptor implements MethodInterceptor, Serializable {
 
		public Object invoke(MethodInvocation invocation) throws Throwable {
			String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName();
			StopWatch sw = new StopWatch(name);
			sw.start(name);
			try { 
				return invocation.proceed();
			} 
			finally { 
				sw.stop();
 
				System.out.println(sw.shortSummary());
			} 
		} 
 
 
	} 
 
6
CodeRank
This code example shows how to use the following methods:getTotalTimeMillis, start, stop
@Aspect 
public class MethodLogger { 
 
	@Around("execution(* com.earldouglas..*.*(..))") 
	public Object timeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
 
		Object retVal = joinPoint.proceed();
 
		stopWatch.stop();
 
		StringBuffer logMessageStringBuffer = new StringBuffer();
		logMessageStringBuffer.append(joinPoint.getTarget().getClass().getName());
		logMessageStringBuffer.append(".");
		logMessageStringBuffer.append(joinPoint.getSignature().getName());
		logMessageStringBuffer.append("(");
		logMessageStringBuffer.append(joinPoint.getArgs());
		logMessageStringBuffer.append(")");
		logMessageStringBuffer.append(" execution time: ");

6
CodeRank
This code example shows how to use the following methods:start, stop
        } 
    } 
 
    @Test 
    public void minimalStackInvocation() throws Exception { 
        sw.start("Run with Minimal Filter Stack"); 
        runWithStack(minimalStack); 
        sw.stop(); 
    } 
 
    @Test 
    public void fullStackInvocation() throws Exception { 
        sw.start("Run with Full Filter Stack"); 
        runWithStack(fullStack); 
        sw.stop(); 
    } 
 
    /** 
     * Creates data from 1 to N_AUTHORITIES in steps of 10, performing N_INVOCATIONS for each 
     */ 
6
CodeRank
This code example shows how to use the following methods:sleep, getTotalTimeMillis, start, stop,
 
		execLoginFailed(150); 
		Thread.sleep(100);
 
		execLoginFailed(225); 
		Thread.sleep(400);
 
		execLoginFailed(100); 
	} 
 
	@Test
	public void testLoginFailed_MaxBlockTime() throws Exception {
		setConf("blockDelayMs", 100); 
		setConf("maxBlockMs", 200); 
 
		execLoginFailed(100); 
		execLoginFailed(150); 
		execLoginFailed(200); 
		execLoginFailed(200); 
		execLoginFailed(200); 
6
CodeRank
This code example shows how to use the following methods:getTotalTimeMillis, start, stop
    } 
 
    public List<Contact> searchContacts(String keyword, int page, int pageSize) {
        keyword = (keyword == null) ? "" : keyword.toLowerCase();
 
        StopWatch watch = new StopWatch();
        watch.start();
        List<Contact> contacts = contactRepo.searchContacts(keyword, new PageRequest(page, pageSize));
        watch.stop();
        gaugeService.submit("query.by.keyword." + keyword, watch.getTotalTimeMillis());
        counterService.increment("search.by.keyword." + keyword);
         
        return contacts;
    } 
 
    public Contact getContact(String id) {
        return contactRepo.findOne(id);
    } 
 
    @Transactional 
6
CodeRank
This code example shows how to use the following methods:getTotalTimeMillis, start, stop
     * the same variable as unAcceptableDuration 
     *  
     */ 
    @Test  @Ignore("This test requires manual verification that the aspect logged a message")
    public void monitorControlPerformance() { 
        final StopWatch sw = new StopWatch();
        sw.start("test");
 
        mockServiceImpl.foo(unAcceptableDuration + 1, new Pojo());
 
        sw.stop(); 
        assertTrue("method exceeded acceptable duration: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() > unAcceptableDuration);
    } 
 
 
 
} 
5
CodeRank
See Code Examples for Spring Framework StopWatch Methods: