java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:574)
at java.util.Timer.<init>(Timer.java:154)
at java.util.Timer.<init>(Timer.java:122)
at com.mysql.jdbc.Connection.<init>(Connection.java:1441)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.hnxxg.advert.DBUtil.getConnection(DBUtil.java:59)
at com.hnxxg.advert.Common.findInfoById(Common.java:25)
at org.apache.jsp.function_jsp._jspService(function_jsp.java:61)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:393)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:482)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)
代码:
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2010-4-28 10:16:47
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Common.javaCommon.java
package com.hnxxg.advert;import java.sql.*;
import java.util.ArrayList;
import java.util.List;// Referenced classes of package com.hnxxg.advert:
//            DBUtil, Infopublic class Common
{    public Common()
    {
 
    }    public Info findInfoById(int id)
        throws SQLException
    {
     Connection con=null;
     PreparedStatement ps=null;
     ResultSet result=null;
        Info info;
        String sql;
        info = null;
        sql = "select * from TS_ADVER where id = ?";
        try
        {
            con = DBUtil.getInstance().getConnection();
            ps = con.prepareStatement(sql);
            ps.setInt(1, id);
            result = ps.executeQuery();
            if(result.next())
            {
                info = new Info();
                info.setId(result.getInt("id"));
                info.setHit(result.getInt("hit"));
                info.setMaxpoint(result.getInt("maxpoint"));
                info.setUrl(result.getString("url"));
            }
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
         if(result != null)
                result.close();
            if(ps != null)
                ps.close();
            if(con != null)
              con.close();
        }
        return info;
    }    public void addAdver(Info info)
        throws SQLException
    {
     Connection con=null;
     PreparedStatement ps=null;
      ResultSet result=null;
        String sql = "insert into TS_ADVER(id,hit,maxpoint,url) values(?,?,?,?)";
        try
        {
            con = DBUtil.getInstance().getConnection();
            ps = con.prepareStatement(sql);
            ps.setInt(1, info.getId());
            ps.setInt(2, info.getHit());
            ps.setInt(3, info.getMaxpoint());
            ps.setString(4, info.getUrl());
            ps.executeUpdate();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
         if(result != null)
                result.close();
            if(ps != null)
                ps.close();
            if(con != null)
                con.close();
        }
  
    }    public void updateAdver(Info info)
        throws SQLException
    {
     Connection con=null;
     PreparedStatement ps=null;
      ResultSet result=null;
        String sql = "update TS_ADVER set hit = ? , maxpoint = ? ,url = ? where id = ?";
        try
        {
            con = DBUtil.getInstance().getConnection();
            ps = con.prepareStatement(sql);
            ps.setInt(1, info.getHit());
            ps.setInt(2, info.getMaxpoint());
            ps.setString(3, info.getUrl());
            ps.setInt(4, info.getId());
            ps.executeUpdate();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
         if(result != null)
                result.close();
            if(ps != null)
                ps.close();
            if(con != null)
                con.close();
        }
    }    public void deleteInfo(int id)
        throws SQLException
    {
     Connection con=null;
     PreparedStatement ps=null;
      ResultSet result=null;
        String sql = "delete from TS_ADVER where id = ?";
        try
        {
            con = DBUtil.getInstance().getConnection();
            ps = con.prepareStatement(sql);
            ps.setInt(1, id);
            ps.executeUpdate();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
         if(result != null)
                result.close();
            if(ps != null)
                ps.close();
            if(con != null)
                con.close();
        }
    }    public List findAllAdver()
        throws SQLException
    {
     Connection con=null;
     PreparedStatement ps=null;
      ResultSet result=null;
        List list;
        String sql;
        list = new ArrayList();
        sql = "select * from TS_ADVER";
        try
        {
            con = DBUtil.getInstance().getConnection();
            ps = con.prepareStatement(sql);
            Info i;
            for(result = ps.executeQuery(); result.next(); list.add(i))
            {
                i = new Info();
                i.setId(result.getInt("id"));
                i.setHit(result.getInt("hit"));
                i.setMaxpoint(result.getInt("maxpoint"));
                i.setUrl(result.getString("url"));
            }
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
         if(result != null)
                result.close();
            if(ps != null)
                ps.close();
            if(con != null)
                con.close();
        }
        return list;
    } 
}
DBUtil.java
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2010-4-28 10:17:01
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   DBUtil.javapackage com.hnxxg.advert;import java.sql.*;
import java.util.Properties;public class DBUtil
{
    private DBUtil()
        throws Exception
    {
        java.io.InputStream in = getClass().getClassLoader().getResourceAsStream("database.properties");
        Properties prop = new Properties();
        prop.load(in);
        driver = prop.getProperty("driver");
        url = prop.getProperty("url");
        user = prop.getProperty("user");
        password = prop.getProperty("password");
        Class.forName(driver);
    }    public static synchronized DBUtil getInstance()
    {
     try
     {
      if(instance == null)
                 instance = new DBUtil();
             return instance;
     }
       catch(Exception e)
       {
        e.printStackTrace();
       }
        return null;
    }    public Connection getConnection()
        throws SQLException
    {
        Connection con=null;
        try
        {
            con = DriverManager.getConnection(url, user, password);
        }
        catch(SQLException e)
        {
            e.printStackTrace();
            throw e;
        }
        return con;
    }    public void closeConnection(Connection con)
    {
        if(con != null)
            try
            {
                con.close();
            }
            catch(SQLException e)
            {
                e.printStackTrace();
            }
    }    private static DBUtil instance;
    private String driver;
    private String url;
    private String user;
    private String password;
}

解决方案 »

  1.   

    加大内存吧。
    可能是你的select * 返回的结果太多了导致内存溢出。其他倒还看不出有什么问题。
      

  2.   

    用loadrunner 测试你的进程看有问题。 是不是程序问题
      

  3.   

    不是内存不够,是无法创建新的native(这个怎么翻译忘了)线程,查看你的数据库.
    而且你的程序编译不会错,但运行结果是达不到预期效果的.
    if(rs.next())之后,游标会向后移动.................
      

  4.   

    Common.java中有每个方法都有Connection ,最后都关闭了
    DBUtil.java中也有个Connection,这个好像从来没有关闭过
    Common文件中,每次也关闭一下,在看看
    这也是一个问题
      

  5.   

    <Java code>
    试下代码格式化
    </java code>
      

  6.   

    <java>
      import java.utils.*;
    </java>
      

  7.   


    Common.java
    package com.hnxxg.advert;import java.sql.*;
    import java.util.ArrayList;
    import java.util.List;// Referenced classes of package com.hnxxg.advert:
    // DBUtil, Infopublic class Common
    {  public Common()
      {
      
      }  public Info findInfoById(int id)
      throws SQLException
      {
      Connection con=null;
      PreparedStatement ps=null;
      ResultSet result=null;
      Info info;
      String sql;
      info = null;
      sql = "select * from TS_ADVER where id = ?";
      try
      {
      con = DBUtil.getInstance().getConnection();
      ps = con.prepareStatement(sql);
      ps.setInt(1, id);
      result = ps.executeQuery();
      if(result.next())
      {
      info = new Info();
      info.setId(result.getInt("id"));
      info.setHit(result.getInt("hit"));
      info.setMaxpoint(result.getInt("maxpoint"));
      info.setUrl(result.getString("url"));
      }
      }
      catch(SQLException e)
      {
      e.printStackTrace();
      }
      finally
      {
      if(result != null)
      result.close();
      if(ps != null)
      ps.close();
      if(con != null)
      con.close();
      }
      return info;
      }  public void addAdver(Info info)
      throws SQLException
      {
      Connection con=null;
      PreparedStatement ps=null;
      ResultSet result=null;
      String sql = "insert into TS_ADVER(id,hit,maxpoint,url) values(?,?,?,?)";
      try
      {
      con = DBUtil.getInstance().getConnection();
      ps = con.prepareStatement(sql);
      ps.setInt(1, info.getId());
      ps.setInt(2, info.getHit());
      ps.setInt(3, info.getMaxpoint());
      ps.setString(4, info.getUrl());
      ps.executeUpdate();
      }
      catch(SQLException e)
      {
      e.printStackTrace();
      }
      finally
      {
      if(result != null)
      result.close();
      if(ps != null)
      ps.close();
      if(con != null)
      con.close();
      }
       
      }  public void updateAdver(Info info)
      throws SQLException
      {
      Connection con=null;
      PreparedStatement ps=null;
      ResultSet result=null;
      String sql = "update TS_ADVER set hit = ? , maxpoint = ? ,url = ? where id = ?";
      try
      {
      con = DBUtil.getInstance().getConnection();
      ps = con.prepareStatement(sql);
      ps.setInt(1, info.getHit());
      ps.setInt(2, info.getMaxpoint());
      ps.setString(3, info.getUrl());
      ps.setInt(4, info.getId());
      ps.executeUpdate();
      }
      catch(SQLException e)
      {
      e.printStackTrace();
      }
      finally
      {
      if(result != null)
      result.close();
      if(ps != null)
      ps.close();
      if(con != null)
      con.close();
      }
      }  public void deleteInfo(int id)
      throws SQLException
      {
      Connection con=null;
      PreparedStatement ps=null;
      ResultSet result=null;
      String sql = "delete from TS_ADVER where id = ?";
      try
      {
      con = DBUtil.getInstance().getConnection();
      ps = con.prepareStatement(sql);
      ps.setInt(1, id);
      ps.executeUpdate();
      }
      catch(SQLException e)
      {
      e.printStackTrace();
      }
      finally
      {
      if(result != null)
      result.close();
      if(ps != null)
      ps.close();
      if(con != null)
      con.close();
      }
      }  public List findAllAdver()
      throws SQLException
      {
      Connection con=null;
      PreparedStatement ps=null;
      ResultSet result=null;
      List list;
      String sql;
      list = new ArrayList();
      sql = "select * from TS_ADVER";
      try
      {
      con = DBUtil.getInstance().getConnection();
      ps = con.prepareStatement(sql);
      Info i;
      for(result = ps.executeQuery(); result.next(); list.add(i))
      {
      i = new Info();
      i.setId(result.getInt("id"));
      i.setHit(result.getInt("hit"));
      i.setMaxpoint(result.getInt("maxpoint"));
      i.setUrl(result.getString("url"));
      }
      }
      catch(SQLException e)
      {
      e.printStackTrace();
      }
      finally
      {
      if(result != null)
      result.close();
      if(ps != null)
      ps.close();
      if(con != null)
      con.close();
      }
      return list;
      } 
    }