Caused by: java.net.SocketException: 打开的文件过多的解决办法

weblogic下项目报错,项目报错信息如下

Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Error reading source with PublicId: http://112.112.12.15:7001/wsDep-web/webservice/DataExchangeWS?wsdl: java.net.SocketException: 打开的文件过多
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:376)
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:327)
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:311)
	at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:263)
	at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:206)
	at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
	... 15 more
Caused by: java.net.SocketException: 打开的文件过多
	at sun.nio.ch.Net.socket0(Native Method)
	at sun.nio.ch.Net.socket(Net.java:423)
	at sun.nio.ch.Net.socket(Net.java:416)
	at sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:104)
	at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)
	at java.nio.channels.SocketChannel.open(SocketChannel.java:142)
	at weblogic.socket.NIOSocketMuxer.newSocket(NIOSocketMuxer.java:328)
	at weblogic.socket.NIOSocketMuxer.newSocket(NIOSocketMuxer.java:274)
	at weblogic.socket.ChannelSocketFactory.createSocket(ChannelSocketFactory.java:95)
	at weblogic.socket.ChannelSocketFactory.createSocket(ChannelSocketFactory.java:58)
	at weblogic.net.http.HttpClient.openServer(HttpClient.java:391)
	at weblogic.net.http.HttpClient.openServer(HttpClient.java:506)
	at weblogic.net.http.HttpClient.New(HttpClient.java:313)
	at weblogic.net.http.HttpURLConnection.getHttpClient(HttpURLConnection.java:283)
	at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:711)
	at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:37)
	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:371)
	... 20 more
ERROR [startQuartz_Worker-2] org.quartz.core.ErrorLogger.schedulerError(2425) | Job (DEFAULT.updateCrlJob threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'getUserFromYNS' on target class [class cn.com.zhulong.app.quartz.QuartzService] failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'getUserFromYNS' on target class [class cn.com.zhulong.app.quartz.QuartzService] failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
	at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:266)
	at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
	... 1 more
Caused by: javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
	at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:151)
	at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:101)
	at javax.xml.ws.Service.<init>(Service.java:92)
	at cn.com.zhulong.app.exuserclient.DataExchangeWS.<init>(DataExchangeWS.java:52)
	at cn.com.zhulong.app.quartz.QuartzService.getZhuTiByTimeSp(QuartzService.java:361)
	at cn.com.zhulong.app.quartz.QuartzService.getUserFromYNS(QuartzService.java:132)
	at sun.reflect.GeneratedMethodAccessor354.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
	at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:257)
	... 3 more
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
	at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:100)
	at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
	at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
	... 13 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Error reading source with PublicId: http://112.112.12.15:7001/wsDep-web/webservice/DataExchangeWS?wsdl: java.net.SocketException: 打开的文件过多
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:376)
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:327)
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:311)
	at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:263)
	at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:206)
	at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
	... 15 more
Caused by: java.net.SocketException: 打开的文件过多
	at sun.nio.ch.Net.socket0(Native Method)
	at sun.nio.ch.Net.socket(Net.java:423)
	at sun.nio.ch.Net.socket(Net.java:416)
	at sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:104)
	at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)
	at java.nio.channels.SocketChannel.open(SocketChannel.java:142)
	at weblogic.socket.NIOSocketMuxer.newSocket(NIOSocketMuxer.java:328)
	at weblogic.socket.NIOSocketMuxer.newSocket(NIOSocketMuxer.java:274)
	at weblogic.socket.ChannelSocketFactory.createSocket(ChannelSocketFactory.java:95)
	at weblogic.socket.ChannelSocketFactory.createSocket(ChannelSocketFactory.java:58)
	at weblogic.net.http.HttpClient.openServer(HttpClient.java:391)
	at weblogic.net.http.HttpClient.openServer(HttpClient.java:506)
	at weblogic.net.http.HttpClient.New(HttpClient.java:313)
	at weblogic.net.http.HttpURLConnection.getHttpClient(HttpURLConnection.java:283)
	at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:711)
	at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:37)
	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
	at oracle.j2ee.ws.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:371)
	... 20 more

  报此错误是由于系统内核对进程打开文件个数的限制,默认为1024

一、 先从Linux设置入手

(1) 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) 30525
max locked memory       (kbytes, -l) 64
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) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

open files默认是1024

为了使服务器重启设置还能生效, 采取永久改变的方法。

vim /etc/security/limits.conf

在文档最后添加

 

* soft nofile 65535
* hard nofile 65535

 

(2) vim  /etc/pam.d/login

在文档最后添加

 

session required /lib/security/pam_limits.so

之后重启服务器

修改成功,成功解决问题

另外:

查看所有进程的文件打开数

lsof |wc -l    (wc -l表示统计行数  

| 则表示一个管道的意思,可以理解为东西从管道的一边流向另外一边。

 

查看某个进程打开的文件数

lsof -p pid |wc -l


 二、 程序

记得在finally语句块里面关闭资源连接, 如:

 

这种写法有可能会导致资源打开不会被关闭,最好还是写在finally里

 

posted @ 2018-01-10 13:56  昊Zz  阅读(6812)  评论(0编辑  收藏  举报