如何找出系统中执行很慢的类

fxbird 2010-06-30 07:41:02
对于web系统,我觉得用spring可以解决,写个拦截器,记录每个方法的执行时间,写入日志就行了,但对于非web系统呢,假如有个c/s系统,如何着手?
...全文
147 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
liqinghuiyx 2010-07-06
  • 打赏
  • 举报
回复
看题就要回帖的
SNOOPY369 2010-07-06
  • 打赏
  • 举报
回复
使用netbeans,sun官方网站可以下载,和eclipse差不多的IDE。里面有performance profiler,可以定位到method级别,可以看到每个方法运行所需时间,所占内存,cpu等一些信息。
Cappuccino 2010-07-06
  • 打赏
  • 举报
回复
拦截器类文件 WebSessionInterceptor.java

public class WebSessionInterceptor extends HandlerInterceptorAdapter
{
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
{
//获取URL请求的相对路径信息URI的前缀部分,形如:/servlet/test.do的test
String lookupPath = new UrlPathHelper().getLookupPathForRequest(request);
// logger.debug(lookupPath);
WebSession webSession = null;
try
{
webSession = handler.getClass().getDeclaredMethod(lookupPath, HttpServletRequest.class, HttpServletResponse.class)
.getAnnotation(WebSession.class);
}
catch (Exception e)
{
//
}
if (webSession == null) webSession = handler.getClass().getAnnotation(WebSession.class);
//do something...
}
}

spring配置文件 servlet-do.xml
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="interceptors">
<list>
<ref bean="webSessionInterceptor"/>
</list>
</property>
</bean>

<bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

<bean id="webSessionInterceptor" class="frame.web.mvc.WebSessionInterceptor"/>
控制器类文件 MainController.java
@Controller
@WebSession
public class MainController
{
private final Logger logger = LoggerFactory.getLogger(getClass());

@WebSession
@RequestMapping
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception
{
return new ModelAndView("main/index.jsp");
}

@WebSession
@RequestMapping
public ModelAndView make(HttpServletRequest request) throws Exception
{
return new ModelAndView("main/index.jsp");
}
}
请求/main.index.do时,系统能够执行MainController中的方法index,拦截器类也可以根据index方法的参数项来获取Method和Method上声明的Annotation项@WebSession。
ronniegxq 2010-07-06
  • 打赏
  • 举报
回复
不懂帮顶
fxbird 2010-07-06
  • 打赏
  • 举报
回复
ding
copine 2010-07-06
  • 打赏
  • 举报
回复
你需要一个profile工具,例如jprofiler.
是风啊a 2010-07-02
  • 打赏
  • 举报
回复
一般如果慢的话,就跟查询数据库有关,所以也没什么必要……
2010-07-02
  • 打赏
  • 举报
回复
spring可以做到
liguangwen86 2010-07-02
  • 打赏
  • 举报
回复
应该有一个软件可以测试,以前的同事弄过,忘了名字了
xcehn 2010-07-01
  • 打赏
  • 举报
回复
jprofile
[Quote=引用 5 楼 dr_lou 的回复:]

用java_home/bin/jvisualvm.exe看哪个方法或类占用cpu时间最长
[/Quote]
这个怎么用?有啥效果
jackaudrey 2010-07-01
  • 打赏
  • 举报
回复
c/s里照样用spring
fxbird 2010-07-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bao110908 的回复:]
搞笑!Spring 又不是只能用在 B/S 应用中
[/Quote]
spring当然能用在c/s里,但它能使用拦截器吗?c/s有filter吗?除了getBean没看到任何可以用的地方。
wingardium 2010-07-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fxbird 的回复:]
引用 1 楼 qingzhe2008 的回复:
c/s系统照样可以用spring呀

c/s里你怎样使拦截器起作用?
[/Quote]
自己用java.lang.reflect.Proxy实现一个拦截器
dr_lou 2010-07-01
  • 打赏
  • 举报
回复
用java_home/bin/jvisualvm.exe看哪个方法或类占用cpu时间最长
  • 打赏
  • 举报
回复
搞笑!Spring 又不是只能用在 B/S 应用中
fxbird 2010-06-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 qingzhe2008 的回复:]
c/s系统照样可以用spring呀
[/Quote]
c/s里你怎样使拦截器起作用?
qingzhe2008 2010-06-30
  • 打赏
  • 举报
回复
c/s系统照样可以用spring呀

67,516

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧