java socket 最大连接数_java.net.SocketException:没有可用的缓冲区空间(达到最大连接数):connect...

嗨,我正在使用Apache HTTP Client 4.0在HTTPS协议的服务器上上传一些文件.上传的应用程序正在运行24×7.今天突然,它开始抛出这个异常 –

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值