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里

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM