本文整理了Java中org.apache.commons.lang.time.StopWatch
类的一些代码示例,展示了StopWatch
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StopWatch
类的具体详情如下:
包路径:org.apache.commons.lang.time.StopWatch
类名称:StopWatch
[英]StopWatch
provides a convenient API for timings.
To start the watch, call #start(). At this point you can:
It is intended that the output methods #toString() and #getTime() should only be called after stop, split or suspend, however a suitable result will be returned at other points.
NOTE: As from v2.1, the methods protect against inappropriate calls. Thus you cannot now call stop before start, resume before suspend or unsplit before split.
This class is not thread-safe
[中]StopWatch
为计时提供了方便的API。
要启动手表,请调用#start()。此时,您可以:
*#分割()手表以获取时间,同时手表继续在后台运行#unsplit()将删除拆分的效果。此时,这三个选项再次可用。
*挂起手表暂停#resume()允许手表继续运行。暂停和恢复之间的任何时间都不计入总数。此时,这三个选项再次可用。
*#停止()手表以完成计时任务。
输出方法#toString()和#getTime()只应在stop、split或suspend之后调用,但是会在其他点返回合适的结果。
注:从v2开始。1.这些方法可以防止不适当的调用。因此,您现在不能在开始之前调用stop,在暂停之前调用resume,或者在拆分之前调用unsplit。
1.split()、suspend()或stop()不能被调用两次
2.unsplit()只能在手表已拆分时调用()
3.仅当手表已暂停()时,才能调用resume()
4.在不调用reset()的情况下,无法调用start()两次
这个类不是线程安全的
代码示例来源:origin: stackoverflow.com
StopWatch stopWatch = new StopWatch();
stopWatch.getTime();
stopWatch.stop();
stopWatch.start();
代码示例来源:origin: stackoverflow.com
StopWatch stopWatch = new StopWatch("My Stop Watch");
stopWatch.start("initializing");
Thread.sleep(2000); // simulated work
stopWatch.stop();
stopWatch.start("processing");
Thread.sleep(5000); // simulated work
stopWatch.stop();
stopWatch.start("finalizing");
Thread.sleep(3000); // simulated work
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
代码示例来源:origin: stackoverflow.com
StopWatch stopWatch = new StopWatch();
long time = stopWatch.measureAction(() - > {/* Measure stuff here */});
代码示例来源:origin: stackoverflow.com
Set<Class<?>> findAllMessageDrivenClasses() {
final StopWatch sw = new StopWatch();
sw.start();
final Reflections reflections = new Reflections("org.projectx", new TypeAnnotationsScanner());
Set<Class<?>> allMessageDrivens = reflections.getTypesAnnotatedWith(MyMessageDriven.class); // NOTE HERE
sw.stop();
return allMessageDrivens;
}
代码示例来源:origin: stackoverflow.com
import java.util.Arrays;
public class TestStopWatch {
pubic static void main(String args[]){
StopWatch sw=new StopWatch();
long p=sw.start(); //trying to call the start method in the previous class
//code to create and sort array
long q=sw.stop(); //stop method in previous class
System.out.println(sw.getElapsedTime((double)q,(double)p)); //call getElapsedtime and print
}
}
代码示例来源:origin: stackoverflow.com
StopWatch stopWatch = new StopWatch();
stopWatch.start();
...
stopWatch.suspend();
...
stopWatch.resume();
...
stopWatch.stop():
long elapsed = stopWatch.getTime();
代码示例来源:origin: com.atlassian.addon.connect.hercules/hercules-ac
protected ScanResult matchForPatterns(final BufferedReader reader, final Date date)
throws IOException
{
LOGGER.debug("start matching for patterns");
final StopWatch sw = new StopWatch();
sw.start();
final Map<String, PatternMatchSet> results = match(reader, date);
LOGGER.debug("results found: {}", results.size());
return new DefaultScanResult(scanItem, results.values(), Lists.<PropertyScanResult>newArrayList(), sw.getTime());
}
}
代码示例来源:origin: stackoverflow.com
StopWatch stopWatch = new StopWatch();
stopWatch.start();
// Do something
stopWatch.stop();
System.out.println(stopWatch.getTotalTimeMillis());
代码示例来源:origin: commons-lang/commons-lang
/**
* <p>
* Gets a summary of the time that the stopwatch recorded as a string.
* </p>
*
* <p>
* The format used is ISO8601-like, <i>hours</i>:<i>minutes</i>:<i>seconds</i>.<i>milliseconds</i>.
* </p>
*
* @return the time as a String
*/
public String toString() {
return DurationFormatUtils.formatDurationHMS(getTime());
}
代码示例来源:origin: jaxio/generated-projects
@PostConstruct
public void createIndex() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try {
for (Class<?> classToBeIndexed : CLASSES_TO_BE_INDEXED) {
indexClass(classToBeIndexed);
}
} finally {
stopWatch.stop();
log.info("Indexed {} in {}", Arrays.toString(CLASSES_TO_BE_INDEXED), stopWatch.toString());
}
}
代码示例来源:origin: stackoverflow.com
final StopWatch stopwatch = new StopWatch();
stopwatch.start();
LOGGER.debug("Starting long calculations: {}", stopwatch);
...
LOGGER.debug("Time after key part of calcuation: {}", stopwatch);
...
LOGGER.debug("Finished calculating {}", stopwatch);
代码示例来源:origin: jwplayer/southpaw
@Override
public long getLag() {
// Periodically cache the end offset
if(endOffset == null || endOffsetWatch.getTime() > END_OFFSET_REFRESH_MS_DEFAULT) {
Map<TopicPartition, Long> offsets = consumer.endOffsets(Collections.singletonList(new TopicPartition(topicName, 0)));
endOffset = offsets.get(new TopicPartition(topicName, 0));
endOffsetWatch.reset();
endOffsetWatch.start();
}
// Because the end offset is only updated periodically, it's possible to see negative lag. Send 0 instead.
long lag = endOffset - (getCurrentOffset() == null ? 0 : getCurrentOffset());
return lag < 0 ? 0 : lag;
}
代码示例来源:origin: david-schuler/javalanche
public void setTest(String testName) {
testStopWatch.reset();
testStopWatch.start();
currentTest = testName;
}
代码示例来源:origin: stackoverflow.com
StopWatch stopWatch=new StopWatch();
//do Some stuff
stopWatch.getTime()
代码示例来源:origin: stackoverflow.com
org.apache.commons.lang.time.StopWatch sw = new org.apache.commons.lang.time.StopWatch();
System.out.println("getEventFilterTreeData :: Start Time : " + sw.getTime());
sw.start();
// Method execution code
sw.stop();
System.out.println("getEventFilterTreeData :: End Time : " + sw.getTime());
代码示例来源:origin: forcedotcom/phoenix
public void stopStopWatch() throws IOException {
getStopWatch().stop();
instanceLog("STOP");
}
代码示例来源:origin: OpenClinica/OpenClinica
public void stop() {
if (LOG.isDebugEnabled()) {
stopwatch.stop();
long totalTime = stopwatch.getTime();
LOG.debug(String.format(STOP_LABEL, name, totalTime / 60000, (float) (totalTime % 60000) / 1000));
}
}
代码示例来源:origin: forcedotcom/phoenix
public PerformanceLog(String startMessage) throws IOException {
getStopWatch().start();
instanceLog("START: " + startMessage);
}
代码示例来源:origin: NationalSecurityAgency/datawave
public void initializeTimers() {
timers.get(TIMERS.HASNEXT).start();
timers.get(TIMERS.HASNEXT).suspend();
timers.get(TIMERS.SCANNER_ITERATE).start();
timers.get(TIMERS.SCANNER_ITERATE).suspend();
timers.get(TIMERS.SCANNER_START).start();
timers.get(TIMERS.SCANNER_START).suspend();
}
代码示例来源:origin: stackoverflow.com
public class SWTest {
public static void main(String[] args) {
StopWatch stopWatch = new StopWatch();
doSomething();
LOGGER.debug("Execution took in seconds: ", (stopWatch.getElapsedTime());
}
}
内容来源于网络,如有侵权,请联系作者删除!