太多打开文件错误android

太多打开文件错误android,第1张

概述我正在实施一项将文件上传到云服务的服务. 我正在使用OkHttp上传大块文件. 逻辑是这样的,我从服务器获取加载URL和头,然后将块上传到云,依此类推. 大约200个块后我得到这个错误的问题: W/System.err: java.net.ConnectException: failed to connect to piboxdev.blob.core.windows.net/40.118.73. 我正在实施一项将文件上传到云服务的服务.
我正在使用Okhttp上传大块文件.
逻辑是这样的,我从服务器获取加载URL和头,然后将块上传到云,依此类推.
大约200个块后我得到这个错误的问题:

W/System.err: java.net.ConnectException: @R_502_5138@ to connect to piBoxdev.blob.core.windows.net/40.118.73.216 (port 443) after 10000ms: connect @R_502_5138@: EMfile (Too many open files) 04-07 11:10:55.963 4945-5653/? W/StreamManager: DropPing non-bitmap icon from notification. 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at libcore.io.IoBrIDge.connect(IoBrIDge.java:124) 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183) 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456) 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at java.net.socket.connect(Socket.java:882) 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.internal.Platform$AndroID.connectSocket(Platform.java:190) 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.Connection.connectSocket(Connection.java:196) 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.Connection.connect(Connection.java:172) 04-07 11:10:55.977 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.Connection.connectAndSetowner(Connection.java:367) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.OkhttpClIEnt$1.connectAndSetowner(OkhttpClIEnt.java:128) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.internal.http.httpEngine.connect(httpEngine.java:328) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.internal.http.httpEngine.sendRequest(httpEngine.java:245) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.Call.getResponse(Call.java:267) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at com.squareup.okhttp.Call.execute(Call.java:79) 04-07 11:10:55.978 13347-15602/by.set.piBox W/System.err:     at by.set.piBox.upload.uploadService.httpUploadTask.loadToAzure(httpUploadTask.java:254)@H_403_15@  

以下是处理上传的代码:

try {        HashMap<String,String> headers = response.getheaders();        String url = response.getUrl();        if (source==null)            source = Okio.buffer(Okio.source(file));        if (content==null)        content = new ChunkfileRequestbody(source,size,ContentType);        Request.Builder builder = new Request.Builder();        for (Map.Entry<String,String>entry : headers.entrySet()) {          builder.addheader(entry.getKey(),entry.getValue());        }        Request azureRequest =  builder.url(url).put(content).build();        Response azureResponse = clIEnt.newCall(azureRequest).execute();        if (azureResponse.code()/100==2 && shouldContinue) {            Log.e(getClass().getSimplename(),azureResponse.code() + " " + azureResponse.message());            uploadedBodyBytes +=size;            if (uploadedBodyBytes>=totalBodyBytes) {                cleanUp();                confirmUpload();            }            else {                broadcastProgress(uploadedBodyBytes,totalBodyBytes);                upload();            }@H_403_15@  

这是自定义内容正文:

public class ChunkfileRequestbody extends Requestbody {private final String ContentType;private long uploadSize;private BufferedSource source;public ChunkfileRequestbody(BufferedSource source,Long size,String ContentType) {    this.source = source;    this.ContentType = ContentType;    this.uploadSize=size;}@OverrIDepublic long contentLength() {    return uploadSize;}@OverrIDepublic MediaType ContentType() {    return MediaType.parse(ContentType);}@OverrIDepublic voID writeto(BufferedSink sink) throws IOException {        source.readFully(sink.buffer(),uploadSize);        sink.flush();}}@H_403_15@  

这不能是文件处理中的泄漏,因为我只打开一次文件.
内存使用情况似乎也很好.
看起来好像Okhttp无法正确关闭套接字.
我问图书馆的作者,但他们无法帮助解决这个问题.

有人有过类似的东西吗?请帮忙

解决方法 你是如何实例化你的http客户端的?我刚刚解决了这个问题,不是每次都实例化一个新的客户端,而只是创建一个并重用它. 总结

以上是内存溢出为你收集整理的太多打开文件错误android全部内容,希望文章能够帮你解决太多打开文件错误android所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1123768.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存