jboss7,java.lang.OutOfMemoryError:无法创建新的本机线程

发布于 2025-01-06 22:00:18 字数 2400 浏览 1 评论 0原文

我在我的应用程序中使用 jsp-servlet。并在jboss 7.0.2服务器上部署了war。我有一个servlet,它有与数据库相关的代码,并且在几秒钟内被调用很多次(比如500次)。但对于如此多的线程来说,它会失败,jboss 7.0.2 将无法处理这些线程。

我使用的是 64 位 jvm。

我使用 -Xss256k 减小了线程堆栈的大小,但这对我不起作用。

中进行了配置

我在jboss.confwrapper.java.additional.10=-XX:ThreadStackSize=256k

我需要处理jboss7上的2000个线程。

服务器(jboss7.0.2)抛出异常。

java.lang.OutOfMemoryError: unable to create new native thread

 at java.lang.Thread.start0(Native Method)

 at java.lang.Thread.start(Unknown Source)

这是我的 servlet java.lang.OutOfMemoryError: 无法创建新的本机线程

    public class Test extends HttpServlet {

private static final long serialVersionUID = 1L;



public Test() {

    super();

}



protected void doGet(HttpServletRequest request,

          HttpServletResponse response) throws ServletException, IOException   {

    processRequest(request, response);

}



protected void doPost(HttpServletRequest request,

        HttpServletResponse response) throws ServletException, IOException {

    processRequest(request, response);

}



public void processRequest(HttpServletRequest request,

        HttpServletResponse response) {

    Logger log=LoggerFactory.getLogger(feedback.class);



       /*   here is my code to insert the data in database. */



            TestClass testobj = new TestClass();       



            testobj.setparam("");





    smsmanager1.add(sms);



    smsmanager1 = null;

    sms = null;





}

  }

代码 fot add 方法

   public void add(T obj) {

         SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

         Session session=sessionFactory.openSession();

         Transaction transaction = null;

         try {

                 transaction = session.beginTransaction();

                 session.save(obj);

                 transaction.commit();

                 session.flush();



         } catch (HibernateException e) {

             if(transaction!=null){

                 transaction.rollback();}

                 e.printStackTrace();

         } finally {

             if(session!=null){

                 session.close();}

                 session = null;

                 transaction = null;

         }

我已经测试了只有一个控制台打印语句的空白 servlet。它工作正常,但不适用于上述 servlet。

我在正确的轨道上吗?

服务器如何处理超过 500-800 个线程的此类 servlet?

I am using the jsp-servlet in my application. and deployed the war on jboss 7.0.2 server. i have servlet have code related to database and that is being called many time in sec (say 500 times). but it is falling over for such many threads, jboss 7.0.2 will not able to handle this threads.

I am using the 64 bit jvm.

I have reduce the size of the thread stack with -Xss256k, this not work for me.

i did the configuration in jboss.conf

wrapper.java.additional.10=-XX:ThreadStackSize=256k

I need to handle the 2000 threads on jboss7.

server (jboss7.0.2) throws an exception.

java.lang.OutOfMemoryError: unable to create new native thread

 at java.lang.Thread.start0(Native Method)

 at java.lang.Thread.start(Unknown Source)

Here is my servlet java.lang.OutOfMemoryError: unable to create new native thread

    public class Test extends HttpServlet {

private static final long serialVersionUID = 1L;



public Test() {

    super();

}



protected void doGet(HttpServletRequest request,

          HttpServletResponse response) throws ServletException, IOException   {

    processRequest(request, response);

}



protected void doPost(HttpServletRequest request,

        HttpServletResponse response) throws ServletException, IOException {

    processRequest(request, response);

}



public void processRequest(HttpServletRequest request,

        HttpServletResponse response) {

    Logger log=LoggerFactory.getLogger(feedback.class);



       /*   here is my code to insert the data in database. */



            TestClass testobj = new TestClass();       



            testobj.setparam("");





    smsmanager1.add(sms);



    smsmanager1 = null;

    sms = null;





}

  }

code fot add method

   public void add(T obj) {

         SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

         Session session=sessionFactory.openSession();

         Transaction transaction = null;

         try {

                 transaction = session.beginTransaction();

                 session.save(obj);

                 transaction.commit();

                 session.flush();



         } catch (HibernateException e) {

             if(transaction!=null){

                 transaction.rollback();}

                 e.printStackTrace();

         } finally {

             if(session!=null){

                 session.close();}

                 session = null;

                 transaction = null;

         }

i have tested for the blank servlet that has the only one console printing statement. it works fine but it not work for above servlet.

am i on the right track here ?

how the server will handle the such servlet for above 500-800 threads ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲鸠 2025-01-13 22:00:18

瓦尔莎;

2000 个线程听起来太多了。您没有提到您的目标机器有多少个处理器,但我相信对于 Tomcat,每个处理器的经验最大值约为 200-250 个,因此保守地说,您需要 10 个 [保留 (+)] 处理器来支持 2000 个并发线程。

(+) 我说保留是因为显然您还需要处理器容量来处理其他事情。

更重要的是,请记住每个线程都需要获取、使用和释放数据库连接,因此不太可能您的应用程序服务器或数据库可以实现或维持这种吞吐量。如果您只是尝试分配这些资源,您的系统就会陷入困境,并开始出现您所概述的错误。

我会重新考虑您的方法,并牢记以下前提:

  1. 将 [Tomcat] 线程数限制为 100 X 处理器数。如果您的客户端可以容忍等待而不是错误(如果没有线程立即可用于处理请求),则允许大量积压的请求。
  2. 实现一个数据库连接池,将连接数限制为上面#1 中的最大并发线程数(加上其他活动所需的任何内容)。如果数据库在此负载下承受压力,您可能需要减少连接池大小,并且请求线程将必须等待连接。
  3. 一旦您对拥有可接受的调整应用程序服务器实例感到满意,您就可以通过集群多个节点并实现请求负载平衡来提高可扩展性。

干杯。

附言。这是关于如何计算所需节点数量的很好的演示以满足特定数量和内容的流量。

Varsha;

2000 threads sounds like too many threads. You did not mention how many processors your target machine has, but I believe that for Tomcat, the empirical maximum per processor is around 200-250, so conservatively, you would need 10 [reserved (+)] processors to support 2000 concurrent threads.

(+) I say reserved because obviously you would need processor capacity for other stuff as well.

More importantly, keep in mind that each thread needs to acquire, use and release a database connection, so it is unlikely that either your application server or your database can achieve or sustain this sort of throughput. If you simply attempt to allocate these resources, you will swamp your system and start getting errors like the one you outlined.

I would reconsider your approach with the following premises in mind:

  1. Limit the number of [Tomcat] threads to 100 X processor count. Allow a generous backlog of requests if your clients can tolerate waits instead of errors if no threads are immediately available to handle the request.
  2. Implement a database connection pool that limits the number of connections to the maximum number of concurrent threads from #1 above (plus whatever you need for other activities). If the database stresses under this load, you may need to reduce the connection pool size and request threads will have to wait for a connection.
  3. Once you are satisfied you have an acceptably tuned application server instance, you can ramp up your scalability by clustering multiple nodes and implementing request load balancing.

Cheers.

PS. This is a good presentation on how to calculate the number of required nodes to satisfy a specific quantity and content of traffic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文