code: private void createIndex(final Queue<Callable<Void>> tasks, final NodeDataIndexingIterator iterator,
        final NodeData rootNode, final AtomicLong count, final AtomicLong processing) throws IOException,
        RepositoryException, InterruptedException
     {
        while (iterator.hasNext())
        {
  
           Callable<Void> task = new Callable<Void>()
           {
              public Void call() throws Exception
              {
                 createIndex(iterator, rootNode, count, processing);
                 return null;
              }
           };
  
           if (!tasks.offer(task))
           {
              // All threads have tasks to do so we do it ourself
              createIndex(iterator, rootNode, count, processing);
           }
        }
     }
docs: Creates an index.
  
  @param tasks
  the queue of existing indexing tasks
  @param rootNode
  the root node of the index
  @param iterator
  the NodeDataIndexing iterator
  @param count
  the number of nodes already indexed.
  @throws IOException
  if an error occurs while writing to the index.
  @throws RepositoryException
  if any other error occurs
  @throws InterruptedException
  if thread was interrupted