Hello. I have such a question - is there any limit on the size of the queue of tasks in ThreadPoolExecutor ? If so, what happens if submit to a pool will be called after the maximum queue size has been reached?

    2 answers 2

    There is no limit if you do not put a queue of limited size in it (you can do it through the constructor). And yes, OOM can be obtained in theory, if taxis accumulate in the queue and the queue will swell and take all the memory. Of course, with this, everything will fall.

      The queue will stand, just as if there were no pool at all.

      • That is, there is no limit? Can I submit to OOM execs? - Vladimir
      • Do you have such "heavy" streams? ThreadPoolService - is engaged in their work, and in your case, it is better to handle OOM errors, and generally it is better to process and log them around - Gorets
      • The question is not how heavy the threads are in me, but what will happen if I stupidly start submitting tasks to the pool with 1 thread in a cycle, and they will be faster than they are executed. What happens then? - Vladimir
      • you have confused me, see the streams you can submit as much as you want, they will just wait for the execution queue, and the OOM can cause yours - Gorets
      • Stop, you misunderstand everything. I, after all, are not streams, but tasks that are placed in a queue. The size of this queue interests me. And all these tasks are performed in 1 thread, because the pool to which the submission goes contains 1 stream. - Vladimir