web工程部署在linux服务器上的tomcat出现问题

WHW1984 2009-10-13 10:21:09
昨天还跑的好好的。
今天又出现这个同样的问题。
内存溢出。
看了半天我的代码 没有问题啊。
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: unable to create new native thread
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:64)
org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:745)
java.security.AccessController.doPrivileged(Native Method)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:743)
org.apache.jsp.Index_jsp._jspService(Index_jsp.java:576)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
sun.reflect.GeneratedMethodAccessor163.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:239)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:266)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:157)


root cause

java.lang.OutOfMemoryError: unable to create new native thread
java.lang.Thread.start0(Native Method)
java.lang.Thread.start(Thread.java:574)
java.util.Timer.<init>(Timer.java:154)
java.util.Timer.<init>(Timer.java:122)
com.mysql.jdbc.Connection.<init>(Connection.java:1441)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
java.sql.DriverManager.getConnection(DriverManager.java:525)
java.sql.DriverManager.getConnection(DriverManager.java:171)
dbmanager.DBManager.getConnection(DBManager.java:31)
dbmanager.DBManager.ExcuteQuery(DBManager.java:103)
dao.ProductDao.SelectProductWithImage(ProductDao.java:71)
org.apache.jsp.Index_jsp._jspService(Index_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
sun.reflect.GeneratedMethodAccessor163.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:239)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:266)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:157)

...全文
92 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
WHW1984 2009-10-13
  • 打赏
  • 举报
回复
数据库操作代码如何:
public class DBManager {
private static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
private static final String DATABASE_URL ="jdbc:mysql://url";
public static Connection getConnection()
{
try {
Class.forName(DRIVER_CLASS).newInstance();
} catch(Exception ex){
ex.printStackTrace();
}
Connection conn=null;
try {
conn=DriverManager.getConnection(DATABASE_URL,user,password);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}

public static void CloseConnection(Connection conn,PreparedStatement pStat)
{
try {
if(pStat!=null)
pStat.close();
if(conn!=null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

public static void CloseConnection(ResultSet rs)
{
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

public static ArrayList ExcuteQuery(String sql)
{
ResultSet rs=null;
ArrayList list = null;
PreparedStatement pStat=null;
Connection conn = null;
try {
boolean flag = false;
if (conn == null) {
flag = true;
}
if (conn != null) {
if (conn.isClosed()) {
flag = true;
}
}
if (flag) {
conn=DBManager.getConnection();
}

pStat=conn.prepareStatement(sql);
rs=pStat.executeQuery();
list=openResult(rs);
} catch (SQLException e) {
e.printStackTrace();
} finally{
CloseConnection(conn,pStat);
}
return list;
}

public static ArrayList ExcuteQueryBySql(String sql,Object Product[])
{
ResultSet rs=null;
ArrayList list=null;
Connection conn = null;
PreparedStatement pStat=null;
try {
boolean flag = false;
if (conn == null) {
flag = true;
}
if (conn != null) {
if (conn.isClosed()) {
flag = true;
}
}
if (flag) {
conn=DBManager.getConnection();
}
pStat=conn.prepareStatement(sql);
for(int i=0;i<Product.length;i++)
{
pStat.setObject(i+1, Product[i]);
}
rs=pStat.executeQuery();
list = openResult(rs);
}catch (SQLException e) {
e.printStackTrace();
}finally{
CloseConnection(conn,pStat);
}
return list;
}

public static ArrayList ExcuteBySql(String sql)
{
ResultSet rs=null;
ArrayList list = null;
Connection conn = null;
PreparedStatement pStat=null;
try {
boolean flag = false;
if (conn == null) {
flag = true;
}
if (conn != null) {
if (conn.isClosed()) {
flag = true;
}
}
if (flag) {
conn=DBManager.getConnection();
}
pStat=conn.prepareStatement(sql);
rs=pStat.executeQuery();
list = openResult(rs);
}catch (SQLException e) {
e.printStackTrace();
}finally{
CloseConnection(conn,pStat);
}
return list;
}

private static ArrayList openResult(ResultSet rs) {
if (rs == null) {
return null;
}

ArrayList list = new ArrayList();
try {
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
while (rs.next()) {
if (columnCount == 1) {
list.add(rs.getObject(1));
} else {
Object[] objs = new Object[columnCount];
for (int i = 0; i < columnCount; i++) {
if (rsmd.getColumnType(i + 1) == Types.CLOB) {
objs[i] = rs.getClob(i + 1)
.getSubString(1, 1000000);
}if(rsmd.getColumnType(i + 1) == Types.TIMESTAMP){
objs[i] = rs.getTimestamp(i+1);
}else {
objs[i] = rs.getObject(i + 1);
}

if (objs[i]==null)
objs[i]="";
}
list.add(objs);
}
}
} catch (Exception e) {
CloseConnection(rs);
}
return list;
}
}

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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