生产环境中Java Web Service的方法执行时间的测量 [英] Measuring Method Execution Time for a Java Web Service in a Production Environment

查看:113
本文介绍了生产环境中Java Web Service的方法执行时间的测量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣寻找一种最佳方法来衡量我正在研究的Java Web服务中方法的执行时间.

I'm interested in finding out the best way to measure the execution time of methods within a Java web service I'm working on.

该服务将被部署到多个客户端,并因此在多个不同的生产环境中运行(客户端往往会根据其需求决定具有不同的设置),因此决定该服务应记录执行时间以处理请求以提供一些服务.指示可能存在的性能问题.

The service will be deployed to multiple clients and hence run in multiple different production environments (clients tend to have varying setups as dictacted by their requirements), and its been decided the service should log the execution time for processing requests to provide some indication of possible performance issues.

到目前为止,大多数建议(例如此处 & 此处)我已经看到要在我感兴趣的代码的开头和结尾使用System.currentTimeMillis()并计算经过的时间,但这真的是生产环境中解决此问题的最佳解决方案吗?

So far, most of the suggestions (such as here & here) I've seen are to use System.currentTimeMillis() at the beginning and end of the code I'm interested in and calculate elapsed time, but is that really the best solution to this problem for a production environment?

System.currentTimeMillis()对于测量方法执行时间是否合适,还有其​​他替代方法吗?

How suitable is System.currentTimeMillis() for measuring method execution time, and are there any alternatives?

为明确起见,一项关键要求是,应将此执行度量作为标准部署的一部分进行部署,以收集数据,以便在与性能相关的支持问题出现时可以引用该度量.提出,因为该服务构成了由新旧组件组成的复杂系统的一部分

EDIT 0: To clarify, a key requirement is that this execution measurement should be deployed as part of the standard deployment to collect data so that it can be referred to should a performance related support issue be raised, as the service forms part of a complex system of new and legacy components

推荐答案

您可以使用Spring Framework的"StopWatch"类:

You can use the Spring Framework 'StopWatch' class:

您甚至可以使用AOP,这样您就可以在不更改代码的情况下分析代码

You can even use AOP, this way you can profile code without changing it

这篇关于生产环境中Java Web Service的方法执行时间的测量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆