简体   繁体   English

在Jelly Bean(Android 4.1)中发生错误 - >打开失败:EMFILE(打开文件过多)

[英]In Jelly Bean (Android 4.1) have error occured -> open failed: EMFILE (Too many open files)

I am working on a download application and running multiple thread simultaneously to download fast. 我正在开发下载应用程序并同时运行多个线程以便快速下载。 But i am facing a problem with android 4.1 jelly bean It producing an exception of Too many files are open (open failed: EMFILE (Too many open files)). 但是我遇到了android 4.1 jelly bean的问题它产生了一个例外,打开太多文件(打开失败:EMFILE(太多打开的文件))。 as I know , There could be only 1024 file should be open for one process. 据我所知,一个进程可能只有1024个文件应该打开。 But issues occurs only with jelly bean not with ICS. 但问题只发生在果冻豆而不是ICS上。

Is There any one can please help to resolve these issues. 有没有人可以帮助解决这些问题。 As it is important to download files in more than 10 thread due to lot's files. 由于lot的文件,因此在10个以上的线程中下载文件非常重要。

Please suggest any idea. 请提出任何想法。 To resolve pro grammatically. 以编程方式解决。

There's a hard limit to the number of open files per process on the linux OS. Linux操作系统上每个进程的打开文件数量有一个硬限制。 That number is configurable if you have system level access, but not through Android. 如果您具有系统级访问权限,则该数字是可配置的,但不能通过Android进行配置。 There's nothing to do except write your application so fewer files are open at once. 除了编写应用程序以外,没有什么可做的,因此一次打开的文件更少。

Although realistically, if you're hitting this problem you're probably leaking file handles somewhere. 虽然实际上,如果你遇到这个问题,你可能会在某处泄漏文件句柄。 Make sure you close all the files you open- the limit is on open files concurrently, if you close one you can always open a new one to take its place. 确保关闭所有打开的文件 - 同时打开文件的限制,如果你关闭一个文件,你总是可以打开一个新的文件取而代之。

I encountered the same problem only in Jellybean a few weeks ago and finally found a workaround. 我几周前才在Jellybean遇到同样的问题,最后找到了解决方法。 See https://stackoverflow.com/a/20417556/976367 请参阅https://stackoverflow.com/a/20417556/976367

Maybe httpClient "has more bugs" and is deprecated, but this problem with JellyBean is a showstopper. 也许httpClient“有更多错误”并且已被弃用,但JellyBean的这个问题是一个显而易见的问题。 I am using Ksoap2 so I tried all the suggested answers that I could. 我正在使用Ksoap2所以我尝试了所有建议的答案。

  • System.setProperty("http.keepAlive", "false"); System.setProperty(“http.keepAlive”,“false”);
  • httpTransportSE.getServiceConnection().setRequestProperty("Connection", "close"); httpTransportSE.getServiceConnection()。setRequestProperty(“Connection”,“close”);
  • httpTransportSE.getServiceConnection().disconnect(); httpTransportSE.getServiceConnection()断开();

Nothing worked - my solution was to rollback the version of Ksoap2 I'm using from 3.1.1 to 2.6.5. 没有任何效果 - 我的解决方案是将我使用的Ksoap2版本从3.1.1回滚到2.6.5。 Using 2.6.5 the problem is substantially reduced. 使用2.6.5可以大大减少问题。 Still testing but maybe even solved. 仍然测试,但甚至可能解决。

It may be that the reason the older version of KSoap2 works for me is that it's using httpClient rather than httpUrlConnection. 可能是旧版KSoap2对我有用的原因是它使用的是httpClient而不是httpUrlConnection。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM