本文整理匯總了Java中org.springframework.util.StopWatch.start方法的典型用法代碼示例。如果您正苦於以下問題:Java StopWatch.start方法的具體用法?Java StopWatch.start怎麽用?Java StopWatch.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.StopWatch
的用法示例。
在下文中一共展示了StopWatch.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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
示例2: 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;
}
示例3: 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));
}
示例4: testPrototypeCreationWithDependencyCheckIsFastEnough
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
@Test
public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(LifecycleBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
lbf.registerBeanDefinition("test", rbd);
lbf.addBeanPostProcessor(new LifecycleBean.PostProcessor());
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);
}
示例5: loadAllMetrics
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
private void loadAllMetrics() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
log.info("Loading all metric names from db...");
int totalMetrics = 0;
for (int level = 1; ; level++) {
log.info("Loading metrics for level " + level);
final AtomicInteger levelCount = new AtomicInteger(0);
clickHouseJdbcTemplate.query(
"SELECT name, argMax(status, updated) as last_status " +
"FROM " + metricsTable + " PREWHERE level = ? WHERE status != ? GROUP BY name",
new MetricRowCallbackHandler(levelCount),
level, MetricStatus.AUTO_HIDDEN.name()
);
if (levelCount.get() == 0) {
log.info("No metrics on level " + level + " loading complete");
break;
}
totalMetrics += levelCount.get();
log.info("Loaded " + levelCount.get() + " metrics for level " + level);
if (inMemoryLevelsCount > 0 && level == inMemoryLevelsCount) {
log.info("Loaded first all " + inMemoryLevelsCount + " in memory levels of metric tree");
break;
}
}
stopWatch.stop();
log.info(
"Loaded complete. Total " + totalMetrics + " metrics in " + stopWatch.getTotalTimeSeconds() + " seconds"
);
}
示例6: generateId32
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
@Test
public void generateId32() throws Exception {
int nThreads = 200;
int size = 10000;
CyclicBarrier cyclicBarrier = new CyclicBarrier(nThreads + 1);
StopWatch stopWatch = new StopWatch();
ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
stopWatch.start();
AtomicInteger atomicInteger = new AtomicInteger();
for (int i = 0; i < nThreads; i++) {
executorService.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
cyclicBarrier.await();
for (int j = 0; j < size; j++) {
snowflakeService.generateId32("account");
atomicInteger.incrementAndGet();
}
cyclicBarrier.await();
return null;
}
});
}
cyclicBarrier.await();
cyclicBarrier.await();
stopWatch.stop();
System.out.println(String.format("[%.2f][%d][%.2f]", stopWatch.getTotalTimeSeconds(), atomicInteger.get(),
((nThreads * size) / stopWatch.getTotalTimeSeconds())));
}
示例7: swaggerSpringfoxDocket
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
/**
* Swagger Springfox configuration.
*/
@Bean
public Docket swaggerSpringfoxDocket(JHipsterProperties jHipsterProperties) {
log.debug("Starting Swagger");
StopWatch watch = new StopWatch();
watch.start();
ApiInfo apiInfo = new ApiInfo(
jHipsterProperties.getSwagger().getTitle(),
jHipsterProperties.getSwagger().getDescription(),
jHipsterProperties.getSwagger().getVersion(),
jHipsterProperties.getSwagger().getTermsOfServiceUrl(),
jHipsterProperties.getSwagger().getContact(),
jHipsterProperties.getSwagger().getLicense(),
jHipsterProperties.getSwagger().getLicenseUrl());
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.genericModelSubstitutes(ResponseEntity.class)
.forCodeGeneration(true)
.genericModelSubstitutes(ResponseEntity.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;
}
示例8: initDb
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
protected void initDb() throws LiquibaseException {
StopWatch watch = new StopWatch();
watch.start();
super.afterPropertiesSet();
watch.stop();
log.debug("Started Liquibase in {} ms", watch.getTotalTimeMillis());
}
示例9: measure
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
public T measure(ProceedingJoinPoint joinPoint) throws Throwable {
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
@SuppressWarnings("unchecked")
final T result = (T) joinPoint.proceed();
stopWatch.stop();
final long duration = stopWatch.getLastTaskTimeMillis();
String log = this.buildLog(joinPoint, duration);
logger.debug(log);
submit(duration);
return result;
}
示例10: profileExecution
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
public static <T> T profileExecution(Callable<T> callable) throws Exception {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try {
return callable.call();
}
finally {
stopWatch.stop();
log.debug(stopWatch.prettyPrint());
}
}
示例11: connected
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
@Override
public StopWatch connected(SocketAddress remoteAddress, String remoteName) {
counterService.increment("socket.numConnected");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
return stopWatch;
}
示例12: responsePushed
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
@Override
public StopWatch responsePushed(StopWatch socketWatch, HttpMethod method, String uri,
HttpServerResponse response) {
counterService.increment("responses.pushed");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
return stopWatch;
}
示例13: invokeUnderTrace
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
@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());
}
}
示例14: enqueueRequest
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
@Override
public StopWatch enqueueRequest(StopWatch endpointWatch) {
counterService.increment("requests.queued.active");
counterService.increment("requests.queued.total");
StopWatch taskWatch = new StopWatch();
taskWatch.start();
return taskWatch;
}
示例15: requestBegin
import org.springframework.util.StopWatch; //導入方法依賴的package包/類
@Override
public StopWatch requestBegin(StopWatch endpointWatch, StopWatch socketMetric, SocketAddress localAddress,
SocketAddress remoteAddress, HttpClientRequest request) {
counterService.increment("requests.sent");
StopWatch requestWatch = new StopWatch();
requestWatch.start();
return requestWatch;
}