分享

一个用于列举所有线程的JSP页面,便于调试

 CevenCheng 2011-12-26


一个用于列举所有线程的JSP页面,便于调试

红薯 发布于 2011年01月18日 18时, 3评/1011阅 ( 26人收藏, 收藏 )
这是一个用来显示应用中所有的线程以及其运行状态的JSP页面,无需其他Java类支持,扔到web项目中即可运行。 
标签: JSP

代码片段(1)

[文件] thread.jsp ~ 888B    下载(146)

01<html>
02<head>
03<title>Threads in oschina</title>
04<style>
05body {font-size:8pt;}
06ol {line-height:18px;}
07</style>
08</head>
09<body>
10<strong>java.io.tmpdir:</strong>
11<ul>
12<li><%=System.getProperty("java.io.tmpdir")%></li>
13</ul>
14<br/>
15<strong>Memory:</strong>
16<ol>
17<li>freeMemory=<%=Runtime.getRuntime().freeMemory()/(1024*1024)%>M</li>
18    <li>totalMemory=<%=Runtime.getRuntime().totalMemory()/(1024*1024)%>M</li>
19    <li>maxMemory=<%=Runtime.getRuntime().maxMemory()/(1024*1024)%>M</li>
20</ol>
21<br/>
22<strong>Thread:</strong>
23<ol>
24<%for(Thread t : list_threads()){%>
25<li><%=t.getName()%>(<b><%=t.getState()%></b>) : <%=t.getClass().getName()%></li>
26<%}%>
27</ol>
28<%!
29public static java.util.List<Thread> list_threads(){
30    int tc = Thread.activeCount();
31    Thread[] ts = new Thread[tc];
32    Thread.enumerate(ts);
33    return java.util.Arrays.asList(ts);
34}
35%>
36</body>
37</html>



----------------------------------------


tomcat启动CPU占用很高,Tomcat -6.0.18版本

方小 发表于 1-18 17:42 11个月前, 5回/874阅, 最后回答: 11个月前 (1人收藏 ,收藏 |举报)

开启tomcatCPU占用很高,一直降不下来,今天又好了,请问是为什么啊,谢谢

标签: Tomcat CPU
我想问同样的问题0个人想要问同样的问题 补充话题说明?

    按评价排序 | 显示最新答案 | 回页面顶部共有5个答案 我要回答?

    • 游客
      游客 回答于 2011-01-18 18:25 (11个月前)

      我用的这个版本,没有问题。还是在商用。

      换个6.0的最高版本试试。

    • 红薯
      红薯 回答于 2011-01-18 18:56 (11个月前)

      一般这种问题多半是应用程序导致的。

      首先看看CPU占用高的时候访问是否正常,我之前经常遇见这样的问题,多半是某处代码死循环导致。

      有个办法你试试用下面这个jsp文件看看系统中的线程,看有没有那些跟应用有关的该退出的没退出的。

      http://www.oschina.net/code/snippet_12_2917

    • zhangyou1010
      zhangyou1010 回答于 2011-01-18 20:09 (11个月前)

      引用来自#3楼“红薯”的帖子

      一般这种问题多半是应用程序导致的。

      首先看看CPU占用高的时候访问是否正常,我之前经常遇见这样的问题,多半是某处代码死循环导致。

      有个办法你试试用下面这个jsp文件看看系统中的线程,看有没有那些跟应用有关的该退出的没退出的。

      http://www.oschina.net/code/snippet_12_2917

      请教红薯,是不是状态为TIMED_WAITING 的线程有问题?

    • zhangyou1010
      zhangyou1010 回答于 2011-01-18 20:43 (11个月前)


      Thread:

      1. main(RUNNABLE) : java.lang.Thread
      2. Timer-0(TIMED_WAITING) : java.util.TimerThread
      3. com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
      4. com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
      5. com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
      6. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      7. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      8. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-3(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      9. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      10. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-5(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      11. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-6(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      12. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-7(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      13. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-8(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      14. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      15. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-10(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
      16. ContainerBackgroundProcessor[StandardEngine[Catalina]](TIMED_WAITING) : java.lang.Thread
      17. http-5666-Acceptor-0(RUNNABLE) : java.lang.Thread
      18. TP-Processor1(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      19. TP-Processor2(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      20. TP-Processor3(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      21. TP-Processor4(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      22. TP-Monitor(TIMED_WAITING) : java.lang.Thread
      23. Thread-13(TIMED_WAITING) : com.cache.CacheTimer
      24. Thread-12(TIMED_WAITING) : com.cache.Cache
      25. net.sf.ehcache.CacheManager@1daf0bf(TIMED_WAITING) : java.util.TimerThread
      26. TP-Processor5(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      27. TP-Processor6(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      28. TP-Processor7(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      29. TP-Processor8(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      30. TP-Processor9(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      31. TP-Processor10(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      32. TP-Processor11(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      33. TP-Processor12(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      34. TP-Processor13(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      35. TP-Processor14(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      36. TP-Processor15(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      37. TP-Processor16(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      38. TP-Processor17(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      39. TP-Processor18(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      40. TP-Processor19(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      41. TP-Processor20(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      42. TP-Processor21(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      43. TP-Processor22(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      44. TP-Processor23(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      45. TP-Processor24(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      46. TP-Processor25(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      47. TP-Processor26(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      48. TP-Processor27(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      49. TP-Processor28(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      50. pool-1-thread-1(TIMED_WAITING) : java.lang.Thread
      51. TP-Processor29(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      52. TP-Processor30(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      53. TP-Processor31(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      54. TP-Processor32(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      55. File Reaper(WAITING) : org.apache.commons.io.FileCleaningTracker$Reaper
      56. TP-Processor33(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      57. TP-Processor34(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      58. TP-Processor35(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      59. TP-Processor36(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      60. TP-Processor37(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      61. TP-Processor38(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      62. TP-Processor39(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      63. TP-Processor40(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      64. TP-Processor41(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      65. TP-Processor42(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      66. TP-Processor43(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      67. TP-Processor44(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      68. TP-Processor45(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      69. TP-Processor46(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      70. TP-Processor47(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      71. TP-Processor48(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      72. TP-Processor49(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      73. TP-Processor50(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
      74. TP-Processor51(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      75. TP-Processor52(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
      76. org.springframework.scheduling.quartz.SchedulerFactoryBean#0_QuartzSchedulerThread(TIMED_WAITING) : org.quartz.core.QuartzSchedulerThread 
    • zhangyou1010
      zhangyou1010 回答于 2011-01-18 20:51 (11个月前)

      刚看了下api,感觉还不是很明白。

      线程状态。线程可以处于下列状态之一:

      • NEW
        至今尚未启动的线程处于这种状态。
      • RUNNABLE
        正在 Java 虚拟机中执行的线程处于这种状态。
      • BLOCKED
        受阻塞并等待某个监视器锁的线程处于这种状态。
      • WAITING
        无限期地等待另一个线程来执行某一特定操作的线程处于这种状态。
      • TIMED_WAITING
        等待另一个线程来执行取决于指定等待时间的操作的线程处于这种状态。
      • TERMINATED
        已退出的线程处于这种状态。  



      本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
      转藏 分享 献花(0

      0条评论

      发表

      请遵守用户 评论公约

      类似文章 更多