use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class AbstractHttpServer method start.
// Lifecycle
@Override
public final void start() {
synchronized (this.lifecycleMonitor) {
if (!isRunning()) {
String serverName = getClass().getSimpleName();
if (logger.isDebugEnabled()) {
logger.debug("Starting " + serverName + "...");
}
this.running = true;
try {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
startInternal();
long millis = stopWatch.getTotalTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Server started on port " + getPort() + "(" + millis + " millis).");
}
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
}
}
use of cn.taketoday.util.StopWatch in project today-infrastructure by TAKETODAY.
the class XmlBeanFactoryTests method lookupOverrideMethodsWithSetterInjection.
@Test
void lookupOverrideMethodsWithSetterInjection() {
StandardBeanFactory xbf = new StandardBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.loadBeanDefinitions(OVERRIDES_CONTEXT);
lookupOverrideMethodsWithSetterInjection(xbf, "overrideOneMethod", true);
// Should work identically on subclass definition, in which lookup
// methods are inherited
lookupOverrideMethodsWithSetterInjection(xbf, "overrideInheritedMethod", true);
// Check cost of repeated construction of beans with method overrides
// Will pick up misuse of CGLIB
int howMany = 100;
StopWatch sw = new StopWatch();
sw.start("Look up " + howMany + " prototype bean instances with method overrides");
for (int i = 0; i < howMany; i++) {
lookupOverrideMethodsWithSetterInjection(xbf, "overrideOnPrototype", false);
}
sw.stop();
// System.out.println(sw);
if (!LoggerFactory.getLogger(StandardBeanFactory.class).isDebugEnabled()) {
assertThat(sw.getTotalTimeMillis() < 2000).isTrue();
}
// Now test distinct bean with swapped value in factory, to ensure the two are independent
OverrideOneMethod swappedOom = (OverrideOneMethod) xbf.getBean("overrideOneMethodSwappedReturnValues");
TestBean tb = swappedOom.getPrototypeDependency();
assertThat(tb.getName()).isEqualTo("David");
tb = swappedOom.protectedOverrideSingleton();
assertThat(tb.getName()).isEqualTo("Jenny");
}
use of cn.taketoday.util.StopWatch in project today-framework by TAKETODAY.
the class AbstractHttpServer method start.
// Lifecycle
@Override
public final void start() {
synchronized (this.lifecycleMonitor) {
if (!isRunning()) {
String serverName = getClass().getSimpleName();
if (logger.isDebugEnabled()) {
logger.debug("Starting " + serverName + "...");
}
this.running = true;
try {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
startInternal();
long millis = stopWatch.getTotalTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Server started on port " + getPort() + "(" + millis + " millis).");
}
} catch (Throwable ex) {
throw new IllegalStateException(ex);
}
}
}
}
use of cn.taketoday.util.StopWatch in project today-framework by TAKETODAY.
the class AbstractHttpServer method stop.
@Override
public final void stop() {
synchronized (this.lifecycleMonitor) {
if (isRunning()) {
String serverName = getClass().getSimpleName();
logger.debug("Stopping " + serverName + "...");
this.running = false;
try {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
stopInternal();
logger.debug("Server stopped (" + stopWatch.getTotalTimeMillis() + " millis).");
} catch (Throwable ex) {
throw new IllegalStateException(ex);
} finally {
reset();
}
}
}
}
use of cn.taketoday.util.StopWatch in project today-framework by TAKETODAY.
the class PerformanceMonitorInterceptor method invokeUnderTrace.
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Logger logger) throws Throwable {
String name = createInvocationTraceName(invocation);
StopWatch stopWatch = new StopWatch(name);
stopWatch.start(name);
try {
return invocation.proceed();
} finally {
stopWatch.stop();
writeToLog(logger, stopWatch.shortSummary());
}
}
Aggregations