I create a pool in this way:

pool = new ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(20),new ThreadPoolExecutor.DiscardPolicy()); 

There was such a question: what would the call to pool.submit() return if the task was sent to the account with a larger task queue size, in this case the 21st. Whether it returns normal Future, or null. In javadoc it is said that a RejectedException will be generated, but I have registered DiscardPolicy.

    1 answer 1

    From the documentation:

    It can be reached by the current RejectedExecutionHandler.

    DiscardPolicy is RejectionExecutionHandler , which, quoting:

    Doesn’t have any effect of discarding task

    Ie silently throws this task.

    • It's clear. It is clear what will happen with the task. BUT the question is what will return submit () - the usual Future or null maybe? - Vladimir
    • Polazil on the dock, dug RejectedExecutionException So, I think submit () will not return anything, you need to catch Exception. - avp
    • Hm, Exception will be if RejectedHandler will throw it. I have a RejectedHandler which just drops the task .. - Vladimir
    • And you check (submit ()) and publish the result. - avp
    • one
      Will return the normal Future - Vladimir