當前位置: 首頁>>代碼示例>>Java>>正文


Java StopWatch類代碼示例

本文整理匯總了Java中org.springframework.util.StopWatch的典型用法代碼示例。如果您正苦於以下問題:Java StopWatch類的具體用法?Java StopWatch怎麽用?Java StopWatch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StopWatch類屬於org.springframework.util包,在下文中一共展示了StopWatch類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: responseEnd

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Override
public void responseEnd(StopWatch requestWatch, HttpServerResponse response) {
    requestWatch.stop();
    counterService.increment("responses.count.total");
    int statusCode = response.getStatusCode();
    long totalTimeMillis = requestWatch.getTotalTimeMillis();
    gaugeService.submit("responses.totalTime.all", totalTimeMillis);
    if (statusCode > 400) {
        gaugeService.submit("responses.totalTime.error.all", totalTimeMillis);
        counterService.increment("responses.count.error.total");
        if (statusCode > 500) {
            counterService.increment("responses.count.error.server");
            gaugeService.submit("responses.totalTime.error.server", totalTimeMillis);
        } else {
            counterService.increment("responses.count.error.client");
            gaugeService.submit("responses.totalTime.error.client", totalTimeMillis);
        }
    } else if (statusCode > 300) {
        counterService.increment("responses.count.redirect");
        gaugeService.submit("responses.totalTime.redirect", totalTimeMillis);
    } else if (statusCode > 200) {
        counterService.increment("responses.count.success");
        gaugeService.submit("responses.totalTime.success", totalTimeMillis);
    }
}
 
開發者ID:unbroken-dome,項目名稱:vertx-spring,代碼行數:26,代碼來源:VertxActuatorMetrics.java

示例2: invoke

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Around("@annotation(com.apssouza.monitoring.Monitored)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("callend");
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
            publisher.publishEvent(new MonitoringInvokedEvent(
                    method.getName(),
                    this.accumulatedCallTime
            ));
        }
    } else {
        return joinPoint.proceed();
    }
}
 
開發者ID:apssouza22,項目名稱:java-microservice,代碼行數:26,代碼來源:CallMonitoringAspect.java

示例3: testShutdown

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testShutdown() throws Exception {
    // Prepare
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    GracefulShutdownHook testee = new GracefulShutdownHook(appContext);
    healthCheck.setReady(true);

    // Modify
    testee.run();

    // Test
    asyncSpringContextShutdownDelayedAssert();
    assertEquals(Status.DOWN, healthCheck.health().getStatus());
    verify(appContext, times(1)).close();
    stopWatch.stop();
    assertTrue(stopWatch.getTotalTimeSeconds() >= SHUTDOWN_WAIT_S);
}
 
開發者ID:SchweizerischeBundesbahnen,項目名稱:springboot-graceful-shutdown,代碼行數:19,代碼來源:GracefulShutdownHookTest.java

示例4: watchPerformance

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Around("performance()")
public Object watchPerformance(ProceedingJoinPoint point){
    System.out.println("The service start:");
    StopWatch stopWatch = new StopWatch("performance");
    stopWatch.start(point.getSignature().toString());
    try {
        return point.proceed();
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }finally {
        stopWatch.stop();
        StopWatch.TaskInfo[] taskInfo = stopWatch.getTaskInfo();
        for (StopWatch.TaskInfo info : taskInfo) {
            System.out.println(info.getTaskName());
            System.out.println(info.getTimeMillis());
        }
        System.out.println("The "+point.getSignature().toString()+" run time:"+stopWatch.prettyPrint());
    }

    return null;
}
 
開發者ID:devpage,項目名稱:sharding-quickstart,代碼行數:22,代碼來源:PerformaceMonitor.java

示例5: swaggerSpringfoxDocket

import org.springframework.util.StopWatch; //導入依賴的package包/類
/**
 * Swagger Springfox configuration.
 */
@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket swaggerSpringMvcPlugin = new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .genericModelSubstitutes(ResponseEntity.class)
        .select()
        .paths(regex(DEFAULT_INCLUDE_PATTERN)) // and by paths
        .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return swaggerSpringMvcPlugin;
}
 
開發者ID:VHAINNOVATIONS,項目名稱:BCDS,代碼行數:19,代碼來源:SwaggerConfiguration.java

示例6: testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:AnnotationProcessorPerformanceTests.java

示例7: testPrototypeCreationWithAutowiredPropertiesIsFastEnough

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:AnnotationProcessorPerformanceTests.java

示例8: testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:AnnotationProcessorPerformanceTests.java

示例9: doFilterInternal

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Override
protected void doFilterInternal(HttpServletRequest request,
		HttpServletResponse response, FilterChain chain)
				throws ServletException, IOException {
	StopWatch stopWatch = createStopWatchIfNecessary(request);
	String path = new UrlPathHelper().getPathWithinApplication(request);
	int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
	try {
		chain.doFilter(request, response);
		status = getStatus(response);
	}
	finally {
		if (!request.isAsyncStarted()) {
			stopWatch.stop();
			request.removeAttribute(ATTRIBUTE_STOP_WATCH);
			recordMetrics(request, path, status, stopWatch.getTotalTimeMillis());
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:20,代碼來源:MetricsFilter.java

示例10: testPerformance1

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testPerformance1() {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("integer->string conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	for (int i = 0; i < 4000000; i++) {
		conversionService.convert(3, String.class);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		new Integer(3).toString();
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:DefaultConversionServiceTests.java

示例11: testPerformance2

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testPerformance2() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("list<string> -> list<integer> conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	List<String> source = new LinkedList<String>();
	source.add("1");
	source.add("2");
	source.add("3");
	TypeDescriptor td = new TypeDescriptor(getClass().getField("list"));
	for (int i = 0; i < 1000000; i++) {
		conversionService.convert(source, TypeDescriptor.forObject(source), td);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		List<Integer> target = new ArrayList<Integer>(source.size());
		for (String element : source) {
			target.add(Integer.valueOf(element));
		}
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:GenericConversionServiceTests.java

示例12: testPerformance3

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testPerformance3() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("map<string, string> -> map<string, integer> conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	Map<String, String> source = new HashMap<String, String>();
	source.put("1", "1");
	source.put("2", "2");
	source.put("3", "3");
	TypeDescriptor td = new TypeDescriptor(getClass().getField("map"));
	for (int i = 0; i < 1000000; i++) {
		conversionService.convert(source, TypeDescriptor.forObject(source), td);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		Map<String, Integer> target = new HashMap<String, Integer>(source.size());
		for (Map.Entry<String, String> entry : source.entrySet()) {
			target.put(entry.getKey(), Integer.valueOf(entry.getValue()));
		}
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:GenericConversionServiceTests.java

示例13: testGetValuePerformance

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testGetValuePerformance() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	Map<String, String> map = new HashMap<String, String>();
	map.put("key", "value");
	EvaluationContext context = new StandardEvaluationContext(map);

	ExpressionParser spelExpressionParser = new SpelExpressionParser();
	Expression expr = spelExpressionParser.parseExpression("#root['key']");

	StopWatch s = new StopWatch();
	s.start();
	for (int i = 0; i < 10000; i++) {
		expr.getValue(context);
	}
	s.stop();
	assertThat(s.getTotalTimeMillis(), lessThan(200L));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:MapAccessTests.java

示例14: swaggerSpringfoxDocket

import org.springframework.util.StopWatch; //導入依賴的package包/類
/**
 * Swagger Springfox configuration.
 */
@Bean
public Docket swaggerSpringfoxDocket() {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    Docket docket = new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .securitySchemes(newArrayList(new BasicAuth("test")))
        .genericModelSubstitutes(ResponseEntity.class)
        .forCodeGeneration(true)
        .genericModelSubstitutes(ResponseEntity.class)
        .directModelSubstitute(org.joda.time.LocalDate.class, String.class)
        .directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class)
        .directModelSubstitute(org.joda.time.DateTime.class, Date.class)
        .directModelSubstitute(java.time.LocalDate.class, String.class)
        .directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
        .directModelSubstitute(java.time.LocalDateTime.class, Date.class)
        .select()
        .paths(regex(DEFAULT_INCLUDE_PATTERN))
        .build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return docket;
}
 
開發者ID:aksakalli,項目名稱:todo-spring-angular,代碼行數:28,代碼來源:SwaggerConfiguration.java

示例15: testPrototypeCreationIsFastEnough

import org.springframework.util.StopWatch; //導入依賴的package包/類
@Test
public void testPrototypeCreationIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	lbf.registerBeanDefinition("test", rbd);
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:DefaultListableBeanFactoryTests.java


注:本文中的org.springframework.util.StopWatch類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。