我创建了一个可以打开大量远程资源的服务;很多,我的意思是超过200k /天,但我认为不到1000个连接同时打开。连接到远程资源后,我打开一个输入流来获取文件内容。 有时我得到以下异常
java.net.BindException: Address already in use: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sitodove.varie.ExternalLinksChecker.getWebPage(ExternalLinksChecker.java:121)
at sitodove.varie.ExternalLinksChecker.run(ExternalLinksChecker.java:37)
此服务正常启动,只需几个端口即可满足有限需求,因为它需要提供一些服务。当它运行时,我得到上述异常,可能是什么原因?
答案 0 :(得分:0)
端口已被使用,您尝试再次绑定它。如果您没有尝试两次使用端口,请检查您的应用程序。
答案 1 :(得分:0)
您可能正在尝试打开已经打开的端口。 打开终端类型telnet以查看该端口是否已打开。即。
telnet localhost 9889
尝试:: 1 ...
telnet:connect to address :: 1:连接被拒绝 如果此命令返回Connection refused,则表示该端口是空闲的。