这是一个用来显示应用中所有的线程以及其运行状态的JSP页面,无需其他Java类支持,扔到web项目中即可运行。<
html
>
<
head
>
<
title
>Threads in oschina</
title
>
<
style
>
body {font-size:8pt;}
ol {line-height:18px;}
</
style
>
</
head
>
<
body
>
<
strong
>java.io.tmpdir:</
strong
>
<
ul
>
<
li
><%=System.getProperty("java.io.tmpdir")%></
li
>
</
ul
>
<
br
/>
<
strong
>Memory:</
strong
>
<
ol
>
<
li
>freeMemory=<%=Runtime.getRuntime().freeMemory()/(1024*1024)%>M</
li
>
<
li
>totalMemory=<%=Runtime.getRuntime().totalMemory()/(1024*1024)%>M</
li
>
<
li
>maxMemory=<%=Runtime.getRuntime().maxMemory()/(1024*1024)%>M</
li
>
</
ol
>
<
br
/>
<
strong
>Thread:</
strong
>
<
ol
>
<%for(Thread t : list_threads()){%>
<
li
><%=t.getName()%>(<
b
><%=t.getState()%></
b
>) : <%=t.getClass().getName()%></
li
>
<%}%>
</
ol
>
<%!
public static java.util.List<
Thread
> list_threads(){
int tc = Thread.activeCount();
Thread[] ts = new Thread[tc];
Thread.enumerate(ts);
return java.util.Arrays.asList(ts);
}
%>
</
body
>
</
html
>
-----------------------------------------------------------------
很多朋友碰到怎样的问题:tomcat启动CPU占用很高,Tomcat -6.0.18版本,本网通过互联网收集了以下的答案,以方便用户参考解决问题,具体问题如下:
开启tomcatCPU占用很高,一直降不下来,今天又好了,请问是为什么啊,谢谢
用户提供的答案1:
我用的这个版本,没有问题。还是在商用。
换个6.0的最高版本试试。
用户提供的答案2:
一般这种问题多半是应用程序导致的。
首先看看CPU占用高的时候访问是否正常,我之前经常遇见这样的问题,多半是某处代码死循环导致。
有个办法你试试用下面这个jsp文件看看系统中的线程,看有没有那些跟应用有关的该退出的没退出的。
http://www.oschina.net/code/snippet_12_2917
用户提供的答案3:
引用来自#3楼“红薯”的帖子
一般这种问题多半是应用程序导致的。
首先看看CPU占用高的时候访问是否正常,我之前经常遇见这样的问题,多半是某处代码死循环导致。
有个办法你试试用下面这个jsp文件看看系统中的线程,看有没有那些跟应用有关的该退出的没退出的。
http://www.oschina.net/code/snippet_12_2917
用户提供的答案4:
Thread:
- main(RUNNABLE) : java.lang.Thread
- Timer-0(TIMED_WAITING) : java.util.TimerThread
- com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
- com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
- com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-3(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-5(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-6(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-7(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-8(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-10(TIMED_WAITING) : org.quartz.simpl.SimpleThreadPool$WorkerThread
- ContainerBackgroundProcessor[StandardEngine[Catalina]](TIMED_WAITING) : java.lang.Thread
- http-5666-Acceptor-0(RUNNABLE) : java.lang.Thread
- TP-Processor1(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor2(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor3(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor4(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Monitor(TIMED_WAITING) : java.lang.Thread
- Thread-13(TIMED_WAITING) : com.cache.CacheTimer
- Thread-12(TIMED_WAITING) : com.cache.Cache
- net.sf.ehcache.CacheManager@1daf0bf(TIMED_WAITING) : java.util.TimerThread
- TP-Processor5(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor6(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor7(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor8(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor9(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor10(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor11(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor12(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor13(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor14(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor15(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor16(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor17(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor18(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor19(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor20(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor21(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor22(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor23(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor24(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor25(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor26(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor27(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor28(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- pool-1-thread-1(TIMED_WAITING) : java.lang.Thread
- TP-Processor29(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor30(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor31(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor32(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- File Reaper(WAITING) : org.apache.commons.io.FileCleaningTracker$Reaper
- TP-Processor33(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor34(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor35(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor36(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor37(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor38(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor39(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor40(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor41(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor42(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor43(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor44(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor45(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor46(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor47(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor48(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor49(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor50(WAITING) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor51(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- TP-Processor52(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
- org.springframework.scheduling.quartz.SchedulerFactoryBean#0_QuartzSchedulerThread(TIMED_WAITING) : org.quartz.core.QuartzSchedulerThread
用户提供的答案5:
刚看了下api,感觉还不是很明白。
线程状态。线程可以处于下列状态之一:
-
NEW
至今尚未启动的线程处于这种状态。
-
RUNNABLE
正在 Java 虚拟机中执行的线程处于这种状态。
-
BLOCKED
受阻塞并等待某个监视器锁的线程处于这种状态。
-
WAITING
无限期地等待另一个线程来执行某一特定操作的线程处于这种状态。
-
TIMED_WAITING
等待另一个线程来执行取决于指定等待时间的操作的线程处于这种状态。
-
TERMINATED
已退出的线程处于这种状态。