栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

对Java Spring应用程序进行性能分析

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

对Java Spring应用程序进行性能分析

我已经使用Spring AOP做到了。

有时,我需要有关在项目中执行某些方法(例如,控制器的方法)花费多少时间的信息。

在servlet xml中,我把

<aop:aspectj-autoproxy/>

另外,我需要为方面创建类:

@Component@Aspectpublic class SystemArchitecture {    @Pointcut("execution(* org.mywebapp.controller..*.*(..))")    public void businessController() {    }}

和探查器方面:

@Component@Aspectpublic class TimeExecutionProfiler {    private static final Logger logger = LoggerFactory.getLogger(TimeExecutionProfiler.class);    @Around("org.mywebapp.util.aspects.SystemArchitecture.businessController()")    public Object profile(ProceedingJoinPoint pjp) throws Throwable {        long start = System.currentTimeMillis();        logger.info("ServicesProfiler.profile(): Going to call the method: {}", pjp.getSignature().getName());        Object output = pjp.proceed();        logger.info("ServicesProfiler.profile(): Method execution completed.");        long elapsedTime = System.currentTimeMillis() - start;        logger.info("ServicesProfiler.profile(): Method execution time: " + elapsedTime + " milliseconds.");        return output;    }    @After("org.mywebapp.util.aspects.SystemArchitecture.businessController()")    public void profileMemory() {        logger.info("JVM memory in use = {}", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));    }}

就这样。当我从Web应用程序请求页面时,有关方法执行时间和JVM内存使用情况的信息会在我的Web应用程序的日志文件中打印出来。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/453515.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号