code: public Task poll(long timeout, TimeUnit unit) throws InterruptedException
     {
        lock.lockInterruptibly();
  
        try
        {
           // wait for the set to be not empty
           timeout = unit.toNanos(timeout);
           while (this.dormant.size() == 0)
           {
              _logger.trace("Task set empty; waiting for new task to be added");
              if (timeout > 0)
              {
                 // "notEmpty" is notified whenever a task is added to the set
                 timeout = notEmpty.awaitNanos(timeout);
              }
              else
              {
                 return null;
              }
           }
  
           // wait until the next task is not blocked
           while (this.blocked(this.dormant.get(0)))
           {
              _logger.trace("Next task blocked; waiting for other tasks to finish");
              if (timeout > 0)
              {
                 // "unblocked" is notified whenever a task is finished or a new task is
                 // added to the set. We wait on that before checking if this task is still
                 // blocked.
                 timeout = unblocked.awaitNanos(timeout);
              }
              else
              {
                 return null; // a timeout occurred
              }
           }
  
           TaskContainer container = this.dormant.remove(0);
           this.enabled.add(container);
  
           if (_logger.isDebugEnabled())
           {
              _logger.debug("Enabling command: " + container.getCommand());
              _logger.debug("Dormant task set: " + this.dormant);
           }
  
           return container;
        }
        finally
        {
           lock.unlock();
        }
     }
docs: Retrieves and removes the task at the head of the queue. Blocks on both an empty set and all
  blocking boundaries specified in SAM-2.
  <p>
  The maximum wait time is twice the timeout. This occurs because first we wait for the set to
  be not empty, then we wait for the task to be unblocked.