@Override
      public void drain() {
        T item;
        while ((item = pending.poll()) != null || working.get() > 0) {
          if (item == null) {
            try {
              item = pending.poll(100, TimeUnit.MILLISECONDS);
              if (item == null && working.get() <= 0) {
                break;
              }
            } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
              break;
            }
          }
          if (item != null) {
            consumer.accept(item);
          }
        }
      }
A handle for each worker thread to offer new items, and drain the remaining ones when done.
planetiler-core/src/main/java/com/onthegomap/planetiler/worker/Distributor.java