您好我正在使用Apache HTTP客戶端4.0上基於HTTPS協議的服務器上的某些文件。上傳的應用程序全天候運行。今天突然它開始拋出這個異常 -java.net.SocketException:沒有可用的緩衝區空間(達到最大連接數?):connect
java.net.SocketException: No buffer space available (maximum connections reached?): connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:333)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:123)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:101)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:381)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
任何人都可以請幫助我嗎?我對發生的事情完全無能爲力?
這是上傳文件的源代碼 -
public File call() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
try{
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
/*
* Create POST REQUEST
*/
HttpPost httpPost = new HttpPost(this.URL);
/*
* Create MultipartRequestEntity
*/
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
/*
* Add POST Parameters
*/
multipartEntity.addPart(parameters[0], this.fileBody);
multipartEntity.addPart(parameters[1], new StringBody(this.TYPE));
multipartEntity.addPart(parameters[2], new StringBody(this.MAAID));
/*
* Add this POST Method
*/
httpPost.setEntity(multipartEntity);
/*
* Upload the file
*/
HttpResponse response = httpclient.execute(httpPost);
int responseCode = response.getStatusLine().getStatusCode();
logger.info("Response Code of HTTP Connectivity ["+ responseCode + "], " +
"it means ["+ response.getStatusLine().getReasonPhrase()+"]");
/*
* Check the server Response
*/
HttpEntity entity = response.getEntity();
if(entity != null){
String status = EntityUtils.toString(entity);
logger.info("Status of file upload from Server >>"+ status+"<<");
entity.consumeContent();
if(status.equalsIgnoreCase("OK")){
return this.fileBody.getFile();
}
}else{
logger.error("Unable to retrieve status of file upload from server");
}
}catch(NoRouteToHostException e){
logger.error("Internet connection to ["+ this.URL + "] is not available", e);
}catch(SocketException e){
logger.error("Unable to connect to "+ this.URL, e);
}catch (Exception e) {
logger.error("Exception while uploading the file["+ this.fileBody.getFilename()+ "] on ["+ this.URL+"]", e);
}finally{
try{
httpclient.getConnectionManager().shutdown();
}catch(Exception e){
// Ignore this exception
}
}
return null;
}
這是什麼操作系統? – Jacob 2011-05-20 06:54:31
微軟Windows Server 2003,32位機器 – user381878 2011-05-20 07:05:11
一個額外的信息- 日誌顯示,這個異常被拋出16次,因爲主程序每個小時都會調用這個上傳程序。第17次,它拋出了一個新的異常: java.net.BindException:地址已在使用中:connect – user381878 2011-05-20 07:07:04