日期:2014-05-17  浏览次数:20773 次

web项目搞活动,每次定点抢购的时候就会特别的卡。166个线程....
web项目搞活动,每次定点抢购的时候就会特别的卡,166个线程,有详细的线程状态。
tomcat cpu不高10-20,我就想是不是线程多了的问题。。不知道代码那个地方会出这种问题
我只有获得数据库连接的时候才用到了锁,这个有没有关系呢.....
帅哥美女们,请问我该怎么解决呢..先谢了啊
这是我测试线程的jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title>Threads in ldcstudy.com</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>

--------------------------------------------
运行后的效果:
 java.io.tmpdir:

    /tmp/tomcat6-tomcat6-tmp


Memory:(我感觉这里内存小了,我不确定,服务器也不在我这,不好调

    freeMemory=21M
    totalMemory=123M
    maxMemory=123M

Thread:(166个线程,现在好多WAITING,抢购的时候全是RUNNABLE)

    main(RUNNABLE) : java.lang.Thread
    ContainerBackgroundProcessor[StandardEngine[Catalina]](TIMED_WAITING) : java.lang.Thread
    http-8080-Acceptor-0(RUNNABLE) : java.lang.Thread
    TP-Processor4(RUNNABLE) : org.apache.tomcat.util.threads.ThreadWithAttributes
    TP-Monitor(TIMED_WAITING) : java.lang.Thread
    C3P0PooledConnectionPoolManager[identityToken->gbrh6o8t1ih5axwrsdxbe|ed9f275, dataSourceName->antuso_itao]-HelperThread-#0(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
    C3P0PooledConnectionPoolManager[identityToken->gbrh6o8t1ih5axwrsdxbe|ed9f275, dataSourceName->antuso_itao]-HelperThread-#1(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
    C3P0PooledConnectionPoolManager[identityToken->gbrh6o8t1ih5axwrsdxbe|ed9f275, dataSourceName->antuso_itao]-HelperThread-#2(TIMED_WAITING) : com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread
    MySQL Sta