org.springframework.util.StopWatch.getLastTaskTimeMillis()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(290)

本文整理了Java中org.springframework.util.StopWatch.getLastTaskTimeMillis()方法的一些代码示例,展示了StopWatch.getLastTaskTimeMillis()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StopWatch.getLastTaskTimeMillis()方法的具体详情如下:
包路径:org.springframework.util.StopWatch
类名称:StopWatch
方法名:getLastTaskTimeMillis

StopWatch.getLastTaskTimeMillis介绍

[英]Return the time taken by the last task.
[中]返回上一个任务所用的时间。

代码示例

代码示例来源:origin: spring-projects/spring-integration-samples

@Override
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
  StopWatchHolder holder = this.stopWatchHolder.get();
  if (holder != null) {
    holder.getStopWatch().stop();
    Stats stats = this.statsMap.get(holder.getType());
    if (stats == null) {
      stats = this.statsMap.get(Object.class);
    }
    stats.add(holder.getStopWatch().getLastTaskTimeMillis());
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void failureToStartBeforeGettingTimings() {
  exception.expect(IllegalStateException.class);
  sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated around advice invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  assertEquals(68, adrian.getAge());
  for (int i = 0; i < howmany; i++) {
    adrian.getAge();
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated after returning advice invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  Advised a = (Advised) adrian;
  assertTrue(a.getAdvisors().length >= 3);
  // Hits joinpoint
  adrian.setAge(25);
  for (int i = 0; i < howmany; i++) {
    adrian.setAge(i);
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated before advice invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  Advised a = (Advised) adrian;
  assertTrue(a.getAdvisors().length >= 3);
  assertEquals("adrian", adrian.getName());
  for (int i = 0; i < howmany; i++) {
    adrian.getName();
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

private long testMix(String file, int howmany, String technology) {
  ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
  StopWatch sw = new StopWatch();
  sw.start(howmany + " repeated mixed invocations with " + technology);
  ITestBean adrian = (ITestBean) bf.getBean("adrian");
  assertTrue(AopUtils.isAopProxy(adrian));
  Advised a = (Advised) adrian;
  assertTrue(a.getAdvisors().length >= 3);
  for (int i = 0; i < howmany; i++) {
    // Hit all 3 joinpoints
    adrian.getAge();
    adrian.getName();
    adrian.setAge(i);
    // Invoke three non-advised methods
    adrian.getDoctor();
    adrian.getLawyer();
    adrian.getSpouse();
  }
  sw.stop();
  System.out.println(sw.prettyPrint());
  return sw.getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-framework

assertEquals(1024, target.getArray().length);
assertEquals(0, target.getArray()[0]);
long time1 = sw.getLastTaskTimeMillis();
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);
assertEquals(1024, target.getArray().length);
assertEquals(0, target.getArray()[0]);
assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testPollingPartitionsCompletion() throws Exception {
  handler.setThreads(3);
  handler.setPartitions(3);
  handler.setPollingInterval(1000);
  handler.afterPropertiesSet();
  StopWatch stopWatch = new StopWatch();
  stopWatch.start();
  Collection<StepExecution> executions = handler.handle(stepSplitter, stepExecution);
  stopWatch.stop();
  assertEquals(3, executions.size());
  assertEquals(3, count.get());
  assertTrue(stopWatch.getLastTaskTimeMillis() >= 1000);
}

代码示例来源:origin: spring-projects/spring-integration

factory.stop();
watch.stop();
assertTrue("Expected < 10000, was: " + watch.getLastTaskTimeMillis(), watch.getLastTaskTimeMillis() < 10000);
assertTrue(latch1.await(10, TimeUnit.SECONDS));

代码示例来源:origin: spring-projects/spring-integration

@Test
@Ignore // Timing is too short for CI/Travis
public void testNoDelayOnClose() throws Exception {
  TcpNioServerConnectionFactory cf = new TcpNioServerConnectionFactory(0);
  final CountDownLatch reading = new CountDownLatch(1);
  final StopWatch watch = new StopWatch();
  cf.setDeserializer(is -> {
    reading.countDown();
    watch.start();
    is.read();
    is.read();
    watch.stop();
    return null;
  });
  cf.registerListener(m -> false);
  final CountDownLatch listening = new CountDownLatch(1);
  cf.setApplicationEventPublisher(e -> {
    listening.countDown();
  });
  cf.afterPropertiesSet();
  cf.start();
  assertTrue(listening.await(10, TimeUnit.SECONDS));
  Socket socket = SocketFactory.getDefault().createSocket("localhost", cf.getPort());
  socket.getOutputStream().write("x".getBytes());
  assertTrue(reading.await(10, TimeUnit.SECONDS));
  socket.close();
  cf.stop();
  assertThat(watch.getLastTaskTimeMillis(), lessThan(950L));
}

代码示例来源:origin: spring-projects/spring-integration

stopwatch.stop();
logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() +
    " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
stopwatch.start();
" (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");

代码示例来源:origin: metatron-app/metatron-discovery

public static long lastElapsed() {
 return watchThreadLocal.get().getLastTaskTimeMillis();
}

代码示例来源:origin: spring-projects/spring-integration

stopwatch.stop();
logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() +
    " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
stopwatch.start();
" (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");

代码示例来源:origin: spring-projects/spring-integration

stopwatch.stop();
logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() +
    " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
stopwatch.start();
" (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");

代码示例来源:origin: dsyer/spring-boot-aspectj

@Around("execution(private * org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(Object, String, ..)) && args(bean,..)")
public Object bind(ProceedingJoinPoint joinPoint, Object bean) throws Throwable {
  bind.start();
  Object result = joinPoint.proceed();
  bind.stop();
  logger.info("Bind,," + bean.getClass().getName() + ": "
      + bind.getLastTaskTimeMillis());
  return result;
}

代码示例来源:origin: at.researchstudio.sat/won-bot

private Model makeReferringMessage(AgreementProtocolState state, MessageFinder messageFinder, MessageReferrer messageReferrer, TextMessageMaker textMessageMaker) {
  int origPrio = Thread.currentThread().getPriority();
  Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  StopWatch queryStopWatch = new StopWatch();
  queryStopWatch.start("query");
  List<URI> targetUris = messageFinder.findMessages(state); 
  URI[] targetUriArray = targetUris.toArray(new URI[targetUris.size()]);
  queryStopWatch.stop();
  Thread.currentThread().setPriority(origPrio);
  Duration queryDuration = Duration.ofMillis(queryStopWatch.getLastTaskTimeMillis());
  Model messageModel = WonRdfUtils.MessageUtils.textMessage(textMessageMaker.makeTextMessage(queryDuration, state, targetUriArray));
  return messageReferrer.referToMessages(messageModel, targetUriArray);
}

代码示例来源:origin: at.researchstudio.sat/won-core

public Dataset aggregate(){
  if (this.aggregatedDataset != null){
   return this.aggregatedDataset;
  }
  synchronized (this) {
   if (this.aggregatedDataset != null) return this.aggregatedDataset;
   StopWatch stopWatch = new StopWatch();
   stopWatch.start();
   Dataset result = DatasetFactory.createGeneral();
   stopWatch.stop();
   logger.debug("init dataset: " + stopWatch.getLastTaskTimeMillis());
   stopWatch.start();
   this.aggregatedDataset = result;
   if (this.inputStreams == null || this.inputStreams.size() == 0) {
    return this.aggregatedDataset;
   }
   RDFDataMgr.read(result, new SequenceInputStream(Collections.enumeration(Collections.unmodifiableCollection(this
                                                          .inputStreams))),
           this.rdfLanguage);
   stopWatch.stop();
   logger.debug("read dataset: " + stopWatch.getLastTaskTimeMillis());
   return this.aggregatedDataset;
  }
 }
}

代码示例来源:origin: at.researchstudio.sat/won-bot

@Override
protected Model makeSuccessMessage(CrawlConnectionCommandSuccessEvent successEvent) {
  crawlStopWatch.stop();
  Duration crawlDuration = Duration.ofMillis(crawlStopWatch.getLastTaskTimeMillis());
  Dataset conversation = successEvent.getCrawledData();
  return WonRdfUtils.MessageUtils
      .textMessage("Finished crawl in " + getDurationString(crawlDuration) + " seconds. The dataset has "
          + conversation.asDatasetGraph().size() + " rdf graphs.");
}

代码示例来源:origin: at.researchstudio.sat/won-core

@Override
protected void writeInternal(Dataset dataset, HttpOutputMessage httpOutputMessage) throws IOException,
HttpMessageNotWritableException {
 StopWatch stopWatch = new StopWatch();
 stopWatch.start();
 MediaType contentType = httpOutputMessage.getHeaders().getContentType();
 Lang rdfLanguage = mimeTypeToJenaLanguage(contentType, Lang.TRIG);
 WonEtagHelper.setMediaTypeForEtagHeaderIfPresent(contentType, httpOutputMessage.getHeaders());
 RDFDataMgr.write(httpOutputMessage.getBody(), dataset, rdfLanguage);
 //append content type to ETAG header to avoid confusing different representations of the same resource
 httpOutputMessage.getBody().flush();
 stopWatch.stop();
 logger.debug("writing dataset took " + stopWatch.getLastTaskTimeMillis() + " millls");
}

代码示例来源:origin: at.researchstudio.sat/won-bot

private void referToEarlierMessages(EventListenerContext ctx, EventBus bus, Connection con, String crawlAnnouncement, MessageFinder messageFinder, MessageReferrer messageReferrer, TextMessageMaker textMessageMaker) {
  Model messageModel = WonRdfUtils.MessageUtils
      .textMessage(crawlAnnouncement);
  bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
  
  // initiate crawl behaviour
  CrawlConnectionCommandEvent command = new CrawlConnectionCommandEvent(con.getNeedURI(), con.getConnectionURI());
  CrawlConnectionDataBehaviour crawlConnectionDataBehaviour = new CrawlConnectionDataBehaviour(ctx, command, Duration.ofSeconds(60));
  final StopWatch crawlStopWatch = new StopWatch();
  crawlStopWatch.start("crawl");
  AgreementProtocolState state = WonConversationUtils.getAgreementProtocolState(con.getConnectionURI(), ctx.getLinkedDataSource());
  crawlStopWatch.stop();
  Duration crawlDuration = Duration.ofMillis(crawlStopWatch.getLastTaskTimeMillis());
  messageModel = WonRdfUtils.MessageUtils
      .textMessage("Finished crawl in " + getDurationString(crawlDuration) + " seconds. The dataset has "
          + state.getConversationDataset().asDatasetGraph().size() + " rdf graphs.");
  getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel));
  messageModel = makeReferringMessage(state, messageFinder, messageReferrer, textMessageMaker);    
  getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel));
  crawlConnectionDataBehaviour.activate();
}

相关文章