title: Receiving data causes "too many files open"
body: <p>In my client I receive via ZeroMQ a lot of input, which needs to be constantly updated. My server is written in python, but that should not matter. So this is what I do in my <code>MainActivity</code>:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          /********************************NETWORK********************************/
          new NetworkCall().execute("");
      }
  
      private class NetworkCall extends AsyncTask&lt;String, Void, String&gt; {
  
          @Override
          protected String doInBackground(String... params) {
              while (true) {
                  try {
                      ZMQ.Context context = ZMQ.context(1);
  
                      // Connect to server
                      ZMQ.Socket requester = context.socket(ZMQ.REQ);
                      String address = "tcp://xxx.xx.xx.xx";
                      int port = 5000;
                      requester.connect(address + ":" + port);
  
                      // Initialize poll set
                      ZMQ.Poller poller = new ZMQ.Poller(1);
                      poller.register(requester, ZMQ.Poller.POLLIN);
  
                      requester.send("COORDINATES");
  
                      //while (true) {
                      String data;
                      poller.poll();
  
                      data = requester.recvStr();
                      System.out.println(data);
  
                      if (data == null) {
                          try {
                              sleep(100);
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }
                      } requester.close();
                  } catch (IllegalStateException ise) {
                      ise.printStackTrace();
                  }
              }
          }
  
          @Override
          protected void onPostExecute(String result) {
          }
  
          @Override
          protected void onPreExecute() {
          }
  
          @Override
          protected void onProgressUpdate(Void... values) {
          }
      }
  }
  </code></pre>
  
  <p>After executing this code on my device, I'll get like 5-9 input data strings, which I receive from the server, but then the following exception appears:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
                    Process: com.example.viktoria.gazefocus, PID: 31339
                    java.lang.RuntimeException: An error occurred while executing doInBackground()
                        at android.os.AsyncTask$3.done(AsyncTask.java:353)
                        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
                        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
                        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                        at java.lang.Thread.run(Thread.java:764)
                     Caused by: com.example.viktoria.gazefocus.zmq.ZError$IOException: java.io.IOException: Too many open files
                        at com.example.viktoria.gazefocus.zmq.Signaler.makeFdPair(Signaler.java:94)
                        at com.example.viktoria.gazefocus.zmq.Signaler.&lt;init&gt;(Signaler.java:50)
                        at com.example.viktoria.gazefocus.zmq.Mailbox.&lt;init&gt;(Mailbox.java:51)
                        at com.example.viktoria.gazefocus.zmq.Ctx.&lt;init&gt;(Ctx.java:128)
                        at com.example.viktoria.gazefocus.zmq.ZMQ.zmq_ctx_new(ZMQ.java:244)
                        at com.example.viktoria.gazefocus.zmq.ZMQ.zmqInit(ZMQ.java:277)
                        at org.zeromq.ZMQ$Context.&lt;init&gt;(ZMQ.java:269)
                        at org.zeromq.ZMQ.context(ZMQ.java:254)
                        at com.example.viktoria.gazefocus.MainActivity$NetworkCall.doInBackground(MainActivity.java:73)
                        at com.example.viktoria.gazefocus.MainActivity$NetworkCall.doInBackground(MainActivity.java:67)
                        at android.os.AsyncTask$2.call(AsyncTask.java:333)
                        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
                        at java.lang.Thread.run(Thread.java:764) 
                     Caused by: java.io.IOException: Too many open files
                        at sun.nio.ch.IOUtil.makePipe(Native Method)
                        at sun.nio.ch.PipeImpl.&lt;init&gt;(PipeImpl.java:42)
                        at sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:50)
                        at java.nio.channels.Pipe.open(Pipe.java:155)
                        at com.example.viktoria.gazefocus.zmq.Signaler.makeFdPair(Signaler.java:91)
                        at com.example.viktoria.gazefocus.zmq.Signaler.&lt;init&gt;(Signaler.java:50) 
                        at com.example.viktoria.gazefocus.zmq.Mailbox.&lt;init&gt;(Mailbox.java:51) 
                        at com.example.viktoria.gazefocus.zmq.Ctx.&lt;init&gt;(Ctx.java:128) 
                        at com.example.viktoria.gazefocus.zmq.ZMQ.zmq_ctx_new(ZMQ.java:244) 
                        at com.example.viktoria.gazefocus.zmq.ZMQ.zmqInit(ZMQ.java:277) 
                        at org.zeromq.ZMQ$Context.&lt;init&gt;(ZMQ.java:269) 
                        at org.zeromq.ZMQ.context(ZMQ.java:254) 
                        at com.example.viktoria.gazefocus.MainActivity$NetworkCall.doInBackground(MainActivity.java:73) 
                        at com.example.viktoria.gazefocus.MainActivity$NetworkCall.doInBackground(MainActivity.java:67) 
                        at android.os.AsyncTask$2.call(AsyncTask.java:333) 
                        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
                        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
                        at java.lang.Thread.run(Thread.java:764) 
  </code></pre>
  
  <p>Apparently too many files are open. After research (I'm using Ubuntu 16.04) I changed the <code>ulimit</code> with <code>ulimit -n 10000</code>. Still this exception will happen. Sometimes I get more input data, sometimes less. Also if I set something like <code>Executor executor = Executors.newFixedThreadPool(5);</code> into the <code>onCreate()</code> method, nothing will change.</p>
  
  <p>How to overcome this issue? </p>
  
  <p>Thanks for reading!</p>