Out Of Memory Tomcat(无法创建新的本机线程) [英] Out Of Memory Tomcat (unable to create new native thread)

查看:655
本文介绍了Out Of Memory Tomcat(无法创建新的本机线程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的tomcat中的一个连续出现内存错误,我的应用程序部署后,在给出错误tomcat退出(关闭)之后部署了。

I am getting continuously outofmemory error for 1 of my tomcat where my application is deployed after given the error tomcat is exit(shutdow).

我拿了日志文件并且发现了这个

I took the log file and found this

SEVERE: Error allocating socket processor
java.lang.OutOfMemoryError: unable to create new native thread
    at java.lang.Thread.start0(Native Method)
    at java.lang.Thread.start(Thread.java:597)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.start(JIoEndpoint.java:513)
    at org.apache.tomcat.util.net.JIoEndpoint.newWorkerThread(JIoEndpoint.java:744)
    at org.apache.tomcat.util.net.JIoEndpoint.createWorkerThread(JIoEndpoint.java:723)
    at org.apache.tomcat.util.net.JIoEndpoint.getWorkerThread(JIoEndpoint.java:757)
    at org.apache.tomcat.util.net.JIoEndpoint.processSocket(JIoEndpoint.java:789)
    at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:355)
    at java.lang.Thread.run(Thread.java:619)
18 Feb, 2015 5:43:30 PM org.apache.tomcat.util.net.JIoEndpoint createWorkerThread
INFO: Maximum number of threads (750) created for connector with address null and port 80

我在server.xml中使用此连接器设置

I am using this connector settings in the server.xml

<Connector port="80" protocol="HTTP/1.1" 
               connectionTimeout="10000" maxThreads="750" minSpareThreads="50" redirectPort="8443" />

有人可以建议我该怎么办?

Can anybody suggest me what can i do?

线程转储

"http-80-123" daemon prio=6 tid=0x5f5e7400 nid=0xcfc runnable [0x619be000..0x619bf9e8]
   java.lang.Thread.State: RUNNABLE
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at com.microsoft.sqlserver.jdbc.DBComms.receive(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PreparedStatementExecutionRequest.executeStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
    - locked <0x15c69398> (a com.microsoft.sqlserver.jdbc.TDSWriter)

我在20秒内完成了4次线程转储持续时间,发现这个tid一直存在

I have taken 4 thread dump over 20 seconds duration and found this tid alive all the time

我们可以找到这个转储的东西吗?

Can we find something with this dump?

我得到了这个来自线程转储,这表示死锁条件为'BLOCKED',因为我在相同状态下多次获得80-90次

I got this from thread dump is this indicating the deadlock condition 'BLOCKED' since i am getting this several times 80- 90 with same state

"http-80-342" daemon prio=6 tid=0x5c0d7c00 nid=0x1d0c waiting for monitor entry [0x6ee0e000..0x6ee0fce8]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at java.sql.DriverManager.getCallerClass(DriverManager.java:477)
    at java.sql.DriverManager.getConnection(DriverManager.java:576)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at t4u.common.DBConnection.getConnectionToDB(DBConnection.java:32)
    at t4u.functions.CommonFunctions.getProcessID(CommonFunctions.java:1465)


推荐答案


java.lang.OutOfMemoryError:无法创建新的原生线程

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

这意味着你已经遇到了一些限制JVM可以创建的线程数。这可能是操作系统施加的限制,也可能是由于缺乏资源(如内存)。

This means you've hit some limit on the number of threads the JVM can create. This could be an OS imposed limit or it could be due to lack of resources (like memory).

如果是操作系统强加的限制,您可以提高它,假设您具有该系统的访问级别。

If it's an OS imposed limit, you may be able to raise it, assuming you have that level of access to the system.

如果它与内存有关,则需要增加可用内存(在VM上添加更多物理内存或增加内存)或降低每个线程的内存要求。要执行此操作,可以使用JVM的 -Xss 参数更改线程堆栈大小。要找到理想值,请从128K或256K开始,看看是否有任何StackOverflow异常。如果你这样做,请增加直到它们消失。

If it's memory related, you need to either increase the available memory (add more physical or increase memory on your VM) or lower the memory requirement for each thread. To do the later, you can change the thread stack size with the -Xss argument to the JVM. To find the ideal value, start with it as very low, like 128K or 256K, and see if you get any StackOverflow exceptions. If you do, increase until they go away.

这里的另一种可能性是使用不同的Connector实现。您还没有说明您当前正在使用哪一个,但BIO(阻塞IO)连接器每个请求消耗一个线程。根据应用程序的运行情况,如果使用NIO或APR连接器,可能会看到更好的线程利用率(即处理相同数量的请求所需的线程更少)。这里没有足够的信息让我说出这种或那种方式,但你可能想用你的应用程序测试它,看看所需的线程数是否下降。

One other possibility here is to use a different Connector implementation. You haven't said which one you're currently using, but the BIO (blocking IO) Connector consumes one thread per request. Depending on what your application is doing, you may see better thread utilization (i.e. less threads required to handle the same amount of requests) if you use the NIO or APR connectors. There's not enough information here for me to say one way or another, but you might want to test it out with your apps and see if the number of threads required drops.


INFO:为地址为null和端口80的连接器创建的最大线程数(750)

INFO: Maximum number of threads (750) created for connector with address null and port 80

这看起来就像你可能在Tomcat中对线程池的限制。在 conf / server.xml 中检查配置。如果您使用的是Executor,请查找 maxThreads 元件。如果没有,请在Connector元素上查找 maxThreads

This looks like you might be hitting a limit on your thread pool in Tomcat. Check your configuration in conf/server.xml. If you're using an Executor, look for maxThreads on that element. If not, look for maxThreads on the Connector element.

这篇关于Out Of Memory Tomcat(无法创建新的本机线程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆