下面列出了怎么用org.springframework.util.StopWatch的API类实例代码及写法,或者点击链接到github查看源代码。
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();
}
@Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
GenericApplicationContext ctx = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
ctx.refresh();
RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.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);
}
@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);
}
@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);
}
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();
}
@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);
}
@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);
}
@Test
public void testSingletonLookupByNameIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
lbf.freezeConfiguration();
StopWatch sw = new StopWatch();
sw.start("singleton");
for (int i = 0; i < 1000000; i++) {
lbf.getBean("test");
}
sw.stop();
// System.out.println(sw.getTotalTimeMillis());
assertTrue("Singleton lookup took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1000);
}
@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<>();
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<>(source.size());
for (String element : source) {
target.add(Integer.valueOf(element));
}
}
watch.stop();
// System.out.println(watch.prettyPrint());
}
@Test
public void testGetValuePerformance() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
Map<String, String> map = new HashMap<>();
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));
}
@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);
lbf.freezeConfiguration();
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);
}
@Test
public void test_5_2_DistinctCount_20140606() throws Throwable {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1);
filter.put("tradeId", Arrays.asList(new Integer[] {
3205, 3206, 3207, 3208, 3209, 3210, 3212, 3299,
3204, 3203, 3202, 3201, 3211}));
Map<Integer, RoaringBitmap> distinct = miniCube.distinct("postId", true, "tradeId", filter);
stopWatch.stop();
Assert.assertEquals(13, distinct.size());
Assert.assertEquals(277, distinct.get(3209).getCardinality());
Assert.assertEquals(186, distinct.get(3211).getCardinality());
Assert.assertEquals(464, distinct.get(3206).getCardinality());
LOGGER.info(stopWatch.getTotalTimeSeconds() + " used for distinct result {}", distinct.toString());
}
@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());
lbf.freezeConfiguration();
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);
}
public InputStream next() {
ZipArchiveEntry zipEntry = zipEntries.nextElement();
StopWatch sw = new StopWatch(zipEntry.getName());
InputStream feStream = null;
try {
return zipFile.getInputStream(zipEntry);
} catch (IOException e) {
IOUtils.closeQuietly(feStream);
return null;
} finally {
IOUtils.closeQuietly(feStream);
System.out.print(sw.prettyPrint());
}
}
@Test
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("spouse"));
lbf.registerBeanDefinition("test", rbd);
lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
lbf.freezeConfiguration();
TestBean spouse = (TestBean) lbf.getBean("spouse");
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) lbf.getBean("test");
assertSame(spouse, tb.getSpouse());
}
sw.stop();
// System.out.println(sw.getTotalTimeMillis());
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
@Test
public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
lbf.registerBeanDefinition("test", rbd);
lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
lbf.freezeConfiguration();
TestBean spouse = (TestBean) lbf.getBean("spouse");
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) lbf.getBean("test");
assertSame(spouse, tb.getSpouse());
}
sw.stop();
// System.out.println(sw.getTotalTimeMillis());
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
@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();
}
}
}
}
@Test
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("spouse"));
lbf.registerBeanDefinition("test", rbd);
lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
lbf.freezeConfiguration();
TestBean spouse = (TestBean) lbf.getBean("spouse");
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) lbf.getBean("test");
assertSame(spouse, tb.getSpouse());
}
sw.stop();
// System.out.println(sw.getTotalTimeMillis());
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
@Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
GenericApplicationContext ctx = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
ctx.refresh();
RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.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);
}
@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();
}
}
}
}
@Test
@Ignore // TODO re-enable when ConstructorResolver TODO sorted out
public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.getConstructorArgumentValues().addGenericArgumentValue("juergen");
rbd.getConstructorArgumentValues().addGenericArgumentValue("99");
lbf.registerBeanDefinition("test", rbd);
lbf.freezeConfiguration();
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) lbf.getBean("test");
assertEquals("juergen", tb.getName());
assertEquals(99, tb.getAge());
}
sw.stop();
// System.out.println(sw.getTotalTimeMillis());
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
@Around("within(@org.springframework.stereotype.Repository *)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
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();
}
}
} else {
return joinPoint.proceed();
}
}
@Test
public void testSingletonLookupByTypeIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
lbf.freezeConfiguration();
StopWatch sw = new StopWatch();
sw.start("singleton");
for (int i = 0; i < 1000000; i++) {
lbf.getBean(TestBean.class);
}
sw.stop();
// System.out.println(sw.getTotalTimeMillis());
assertTrue("Singleton lookup took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1000);
}
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();
}
@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++) {
Integer.valueOf(3).toString();
}
watch.stop();
// System.out.println(watch.prettyPrint());
}
@Test
public void testGetValuePerformance() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
Map<String, String> map = new HashMap<>();
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));
}
public SnomedTaxonomy buildWithAxiomRefset(InputStreamSet snomedRf2OwlSnapshotArchive) throws ReleaseImportException {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
SnomedTaxonomyLoader snomedTaxonomyLoader = new SnomedTaxonomyLoader();
ReleaseImporter releaseImporter = new ReleaseImporter();
releaseImporter.loadEffectiveSnapshotReleaseFileStreams(snomedRf2OwlSnapshotArchive.getFileInputStreams(), OWL_SNAPSHOT_LOADING_PROFILE, snomedTaxonomyLoader);
snomedTaxonomyLoader.reportErrors();
logger.info("Loaded release snapshot");
logger.info("Time taken deserialising axioms {}s", (snomedTaxonomyLoader.getTimeTakenDeserialisingAxioms() / 1000.00));
stopWatch.stop();
logger.info("SnomedTaxonomy loaded in {} seconds", stopWatch.getTotalTimeSeconds());
SnomedTaxonomy snomedTaxonomy = snomedTaxonomyLoader.getSnomedTaxonomy();
logger.info("{} concepts loaded", snomedTaxonomy.getAllConceptIds().size());
logger.info("{} active axioms loaded", snomedTaxonomy.getAxiomCount());
return snomedTaxonomy;
}
@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();
}
}
/**
* 生成公钥
*
* @author: quhailong
* @date: 2019/9/26
*/
//@RequestMapping(value = "getPublickKey", method = {RequestMethod.GET})
@RequestMapping(value = "getpublickey", method = RequestMethod.GET)
public RestAPIResult<String> getPublicKey() throws Exception {
logger.info("生成公钥请求URL:{}", httpServletRequest.getRequestURL());
StopWatch stopWatch = new StopWatch();
stopWatch.start();
logger.info("生成公钥数据处理开始");
RestAPIResult<String> result = edgeServiceProvider.getPublicKeyHandle();
logger.info("生成公钥数据处理结束,result:{}", result);
stopWatch.stop();
logger.info("生成公钥调用时间,millies:{}", stopWatch.getTotalTimeMillis());
return result;
}
/**
* Writes a log message before the invocation based on the value of {@code enterMessage}.
* If the invocation succeeds, then a log message is written on exit based on the value
* {@code exitMessage}. If an exception occurs during invocation, then a message is
* written based on the value of {@code exceptionMessage}.
* @see #setEnterMessage
* @see #setExitMessage
* @see #setExceptionMessage
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
String name = ClassUtils.getQualifiedMethodName(invocation.getMethod());
StopWatch stopWatch = new StopWatch(name);
Object returnValue = null;
boolean exitThroughException = false;
try {
stopWatch.start(name);
writeToLog(logger,
replacePlaceholders(this.enterMessage, invocation, null, null, -1));
returnValue = invocation.proceed();
return returnValue;
}
catch (Throwable ex) {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
exitThroughException = true;
writeToLog(logger, replacePlaceholders(
this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
throw ex;
}
finally {
if (!exitThroughException) {
if (stopWatch.isRunning()) {
stopWatch.stop();
}
writeToLog(logger, replacePlaceholders(
this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
}
}
}