原文链接:http://www.javaarch.net/jiagoushi/626.htm
java web应用在执行一段时间之后出现了这么个问题
java.net.SocketException: Too many open files at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384) at java.net.ServerSocket.implAccept(ServerSocket.java:453) at java.net.ServerSocket.accept(ServerSocket.java:421) at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60) at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:216)
用ulimit -a看看linux打开文件限制
[admin@test ~]# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 360448 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 360448 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
用lsof -p [进程ID] 可以看到某ID的打开文件状况。进程ID可能用 ps -ef|grep java列出
[admin@test ~]# lsof -p 1940 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME java 1940 admin cwd DIR 0,68 4096 385090717 /admin/apache-tomcat-7.0.39/bin java 1940 admin rtd DIR 0,68 4096 384141801 / java 1940 admin txt REG 0,68 47308 385122308 /admin/jdk1.6.0_13/jre/bin/java java 1940 admin mem REG 202,3 385122339 /admin/jdk1.6.0_13/jre/lib/i386/client/libjvm.so (path dev=0,68) java 1940 admin mem REG 202,3 385122308 /admin/jdk1.6.0_13/jre/bin/java (path dev=0,68) java 1940 admin mem REG 202,3 385122425 /admin/jdk1.6.0_13/jre/lib/i386/client/classes.jsa (path dev=0,68) java 1940 admin mem REG 202,3 385122426 /admin/jdk1.6.0_13/jre/lib/charsets.jar (path dev=0,68) java 1940 admin mem REG 202,3 384959153 /lib/libresolv-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 384959143 /lib/libnss_dns-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 385122355 /admin/jdk1.6.0_13/jre/lib/i386/libnio.so (path dev=0,68) java 1940 admin mem REG 202,3 385122354 /admin/jdk1.6.0_13/jre/lib/i386/libnet.so (path dev=0,68) java 1940 admin mem REG 202,3 385122325 /admin/jdk1.6.0_13/jre/lib/ext/sunjce_provider.jar (path dev=0,68) java 1940 admin mem REG 202,3 385122326 /admin/jdk1.6.0_13/jre/lib/ext/sunpkcs11.jar (path dev=0,68) java 1940 admin mem REG 202,3 385122392 /admin/jdk1.6.0_13/jre/lib/jce.jar (path dev=0,68) java 1940 admin mem REG 202,3 385122405 /admin/jdk1.6.0_13/jre/lib/resources.jar (path dev=0,68) java 1940 admin mem REG 202,3 385122391 /admin/jdk1.6.0_13/jre/lib/jsse.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090820 /admin/apache-tomcat-7.0.39/lib/tomcat-dbcp.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090824 /admin/apache-tomcat-7.0.39/lib/tomcat-jdbc.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090821 /admin/apache-tomcat-7.0.39/lib/tomcat-i18n-es.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090816 /admin/apache-tomcat-7.0.39/lib/jsp-api.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090817 /admin/apache-tomcat-7.0.39/lib/servlet-api.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090813 /admin/apache-tomcat-7.0.39/lib/el-api.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090811 /admin/apache-tomcat-7.0.39/lib/catalina.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090812 /admin/apache-tomcat-7.0.39/lib/ecj-4.2.1.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090819 /admin/apache-tomcat-7.0.39/lib/tomcat-coyote.jar (path dev=0,68) java 1940 admin mem REG 202,3 385122356 /admin/jdk1.6.0_13/jre/lib/i386/libmanagement.so (path dev=0,68) java 1940 admin mem REG 202,3 385122440 /admin/jdk1.6.0_13/jre/lib/rt.jar (path dev=0,68) java 1940 admin mem REG 202,3 384500332 /usr/lib/locale/locale-archive-rpm (path dev=0,68) java 1940 admin mem REG 202,3 385122427 /admin/jdk1.6.0_13/jre/lib/ext/localedata.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090825 /admin/apache-tomcat-7.0.39/lib/tomcat-util.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090807 /admin/apache-tomcat-7.0.39/lib/annotations-api.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090815 /admin/apache-tomcat-7.0.39/lib/jasper.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090818 /admin/apache-tomcat-7.0.39/lib/tomcat-api.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090809 /admin/apache-tomcat-7.0.39/lib/catalina-ha.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090814 /admin/apache-tomcat-7.0.39/lib/jasper-el.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090810 /admin/apache-tomcat-7.0.39/lib/catalina-tribes.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090823 /admin/apache-tomcat-7.0.39/lib/tomcat-i18n-ja.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090822 /admin/apache-tomcat-7.0.39/lib/tomcat-i18n-fr.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090808 /admin/apache-tomcat-7.0.39/lib/catalina-ant.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090794 /admin/apache-tomcat-7.0.39/bin/tomcat-juli.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090781 /admin/apache-tomcat-7.0.39/bin/commons-daemon.jar (path dev=0,68) java 1940 admin mem REG 202,3 385090776 /admin/apache-tomcat-7.0.39/bin/bootstrap.jar (path dev=0,68) java 1940 admin mem REG 202,3 385122350 /admin/jdk1.6.0_13/jre/lib/i386/libzip.so (path dev=0,68) java 1940 admin mem REG 202,3 385122346 /admin/jdk1.6.0_13/jre/lib/i386/libjava.so (path dev=0,68) java 1940 admin mem REG 202,3 384959101 /lib/libnss_files-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 385122345 /admin/jdk1.6.0_13/jre/lib/i386/libverify.so (path dev=0,68) java 1940 admin mem REG 202,3 384959147 /lib/libnsl-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 385222531 /tmp/hsperfdata_admin/1940 (path dev=0,68) java 1940 admin mem REG 202,3 384959158 /lib/librt-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 384959112 /lib/libm-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 384959123 /lib/libc-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 384958823 /lib/libdl-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 385122348 /admin/jdk1.6.0_13/jre/lib/i386/jli/libjli.so (path dev=0,68) java 1940 admin mem REG 202,3 384959167 /lib/libpthread-2.12.so (path dev=0,68) java 1940 admin mem REG 202,3 385122332 /admin/jdk1.6.0_13/jre/lib/i386/native_threads/libhpi.so (path dev=0,68) java 1940 admin mem REG 202,3 384959214 /lib/ld-2.12.so (path dev=0,68) java 1940 admin 0r CHR 1,3 384926820 /dev/null java 1940 admin 1w REG 0,68 26134081 385090804 /admin/apache-tomcat-7.0.39/logs/catalina.out java 1940 admin 2w REG 0,68 26134081 385090804 /admin/apache-tomcat-7.0.39/logs/catalina.out java 1940 admin 3r REG 0,68 28615 385090776 /admin/apache-tomcat-7.0.39/bin/bootstrap.jar java 1940 admin 4r CHR 1,8 384926869 /dev/random java 1940 admin 5r CHR 1,9 384926888 /dev/urandom java 1940 admin 6r REG 0,68 24281 385090781 /admin/apache-tomcat-7.0.39/bin/commons-daemon.jar java 1940 admin 7r REG 0,68 38161 385090794 /admin/apache-tomcat-7.0.39/bin/tomcat-juli.jar java 1940 admin 8r REG 0,68 51139867 385122440 /admin/jdk1.6.0_13/jre/lib/rt.jar java 1940 admin 9w REG 0,68 23357 385090941 /admin/apache-tomcat-7.0.39/logs/catalina.2013-05-29.log java 1940 admin 10w REG 0,68 6736 385090942 /admin/apache-tomcat-7.0.39/logs/localhost.2013-05-29.log java 1940 admin 11w REG 0,68 0 385090943 /admin/apache-tomcat-7.0.39/logs/manager.2013-05-29.log java 1940 admin 12w REG 0,68 0 385090944 /admin/apache-tomcat-7.0.39/logs/host-manager.2013-05-29.log java 1940 admin 13r REG 0,68 54176 385090808 /admin/apache-tomcat-7.0.39/lib/catalina-ant.jar java 1940 admin 14r REG 0,68 48693 385090822 /admin/apache-tomcat-7.0.39/lib/tomcat-i18n-fr.jar java 1940 admin 15r REG 0,68 51678 385090823 /admin/apache-tomcat-7.0.39/lib/tomcat-i18n-ja.jar java 1940 admin 34r REG 0,68 618621 385122391 /admin/jdk1.6.0_13/jre/lib/jsse.jar java 1940 admin 35r REG 0,68 88256 385122392 /admin/jdk1.6.0_13/jre/lib/jce.jar java 1940 admin 36r REG 0,68 226069 385122326 /admin/jdk1.6.0_13/jre/lib/ext/sunpkcs11.jar java 1940 admin 37r REG 0,68 170239 385122325 /admin/jdk1.6.0_13/jre/lib/ext/sunjce_provider.jar java 1940 admin 38u IPv6 221130420 TCP *:http (LISTEN) java 1940 admin 39u sock 0,5 221130418 can't identify protocol java 1940 admin 40u IPv6 221130421 TCP *:8009 (LISTEN) java 1940 admin 41w REG 0,68 15006 385090940 /admin/apache-tomcat-7.0.39/logs/localhost_access_log.2013-05-29.txt java 1940 admin 42u IPv6 221137418 TCP localhost.localdomain:41285->localhost.localdomain:mysql (ESTABLISHED) java 1940 admin 44u IPv6 221132667 TCP localhost.localdomain:mxi (LISTEN) java 1940 admin 46r REG 0,68 311856 384278348 (deleted) /admin/data/_2pb.tis java 1940 admin 47r REG 0,68 148741 384278362 (deleted) /admin/data/_2pb.frq java 1940 admin 48r REG 0,68 311842 384277396 (deleted) /admin/data/_2pc.tis java 1940 admin 87w REG 0,68 4355 388497409 /logs/run.log java 1940 admin 110r CHR 1,8 384926869 /dev/random java 1940 admin 111r REG 0,68 311856 384278348 (deleted) /admin/data/_2pb.tis java 1940 admin 112u unix 0xffff88045ea3b9c0 221132407 socket
ulimit -n 4096 临时把打开文件数的上限设为了4096
如果要永久生效,可以通过下面的方式设置。
修改/etc/security/limits.conf 添加如下一行:
* - nofile 1006154
修改/etc/pam.d/login添加如下一行
session required /lib/security/pam_limits.so
相关推荐
JAVA.NET.SOCKETEXCEPTION TOO MANY OPEN FILES解决方法 JAVA.NET.SOCKETEXCEPTION TOO MANY OPEN FILES错误是一种常见的网络编程错误,发生在Java应用程序中, especialmente 在 Linux 操作系统中。该错误的出现是...
NULL 博文链接:https://zhoudan241.iteye.com/blog/1432014
解决上述问题的关键在于解决最初的`java.net.SocketException`异常,因为一旦解决了这一问题,后续的异常往往也会随之消失。具体步骤如下: 1. **配置JVM参数**:在启动JVM时添加参数`-Djava.net.preferIPv4Stack=...
"java.net.SocketException Connection reset 解决方法" 在 Java 编程中,SocketException 是一种常见的异常,特别是在网络编程中。Conexion reset by peer 是一种特殊的 SocketException,它发生在客户端和服务器...
Java中的`java.net.SocketException: Connection reset`是一个常见的网络编程错误,通常表示在TCP/IP通信过程中,连接突然中断。这个异常可能在客户端或服务器端发生,通常与数据传输的异常中断有关。 首先,我们来...
Linux下运行tomcat或者was出现java.net.SocketException: 打开的文件过多错误 tomcat报“too many open files”的错误,解决办法如下:
接口调用报错:java.net.SocketException: java.lang.ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory
Java Socket编程中,异常处理是确保程序稳定性和健壮性的重要环节。以下是对常见的Java Socket异常的详细解析和处理建议: 1. **java.net....同时,良好的错误处理和日志记录也有助于快速定位和解决问题。
connection reset解决方案(亲测可用).md
在将Web服务器从Windows环境迁移到Linux环境后,遇到了一个常见的问题:“java.net.SocketException: Too many open files”。这种异常通常发生在高并发环境下,例如网站访问量显著增加时。在Windows环境中长时间...
在Java中使用FastDFS,首先需要在项目中引入FastDFS的Java客户端库。配置client.conf文件,设置tracker服务器的地址和其他相关参数。接着创建FastdfsClient和FastdfsUtil类,前者用于与FastDFS服务器通信,后者封装...
项目中碰到的,记录一下解决方案
Caused by: java.net.ConnectException: Connection refused at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:574) at ...
```java RequestQueue queue = Volley.newRequestQueue(this); ``` 2. 创建Request对象:根据实际需求创建对应的Request子类,如StringRequest、JsonArrayRequest等。 ```java String url = ...
Hive是Apache软件基金会开发的一个开源大数据处理框架,它基于Hadoop,主要用于存储、管理和分析大规模数据集。下面我们将详细探讨Socket与Hive数据同步的相关知识点。 1. **Socket基础**: Socket是网络通信中的...
java.net.SocketException: Connection reset by peer: Socket write error 该异常可能发生在客户端和服务器端,原因是因为一端的 Socket 被关闭,而另一端继续发送数据。解决方法是确保在关闭连接前完成所有的数据...
3. 错误信息:当Socket连接池出现问题时,可能会出现错误信息,如"java.net.SocketException: No buffer space available (maximum connections reached?): listen failed"。 解决方法 要解决线程太多导致Socket...
在PDA开发时经常会遇到下面的错误,原因是缺少一个dll,只要在项目中引用这个dll就可以获得错误的描述,然后根据错误提示在解决问题!System.Net.WebException: 无法显示错误消息,原因是无法找到包含此错误消息的可...
错误展示: 我在本地是可以发送的但部署到服务器上后就不能...分析: 邮件发送相关端口 首先说下邮件发送的端口:25/465/587 25端口 25端口是为SMTP协议服务开放的,是这三个端口中最老的一个。25端口也称为消息中继端