Package com.saxonica.ee.optim

## Class MultithreadedItemMappingIterator

- java.lang.Object
- - net.sf.saxon.expr.ItemMappingIterator
  - - com.saxonica.ee.optim.MultithreadedItemMappingIterator

- All Implemented Interfaces:
    `java.io.Closeable`, `java.lang.AutoCloseable`, `LastPositionFinder`, `SequenceIterator`, `LookaheadIterator`

      public class MultithreadedItemMappingIterator
      extends ItemMappingIterator

  Parallel-processing version of the ItemMappingIterator class, which executes a mapping function for each item in a sequence. In this implementation (which is designed initially for use by the collection() function), the order of items in the result sequence retains the order of items in the input sequence.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface net.sf.saxon.om.SequenceIterator

      `SequenceIterator.Property`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `MultithreadedItemMappingIterator​(SequenceIterator base, ItemMappingFunction action, MultithreadingFactory factory)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close()` | The user of a `SequenceIterator` is encouraged to call the `close()` method if no further items are required from the sequence of items delivered by the `SequenceIterator`.
    `protected int` | `getMaxThreads()` | Overridable method that decides how many threads to use.
    `Item` | `next()` | Get the next item in the sequence.

    - ### Methods inherited from class net.sf.saxon.expr.ItemMappingIterator

      `getBaseIterator, getLength, getMappingFunction, getProperties, hasNext, isOneToOne, setOneToOne`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.om.SequenceIterator

      `forEachOrFail, materialize`

- - ### Constructor Detail

    - #### MultithreadedItemMappingIterator

          public MultithreadedItemMappingIterator​(SequenceIterator base,
                                                  ItemMappingFunction action,
                                                  MultithreadingFactory factory)
                                           throws XPathException

      Throws:
        `XPathException`

  - ### Method Detail

    - #### getMaxThreads

          protected int getMaxThreads()

      Overridable method that decides how many threads to use. The default implementation returns the value of `Runtime.getRuntime().availableProcessors()`, or 1 if greater.
      Returns:
        the maximum number of threads to use.

    - #### next

          public Item next()
                    throws XPathException

      Description copied from interface: `SequenceIterator`
      Get the next item in the sequence. This method changes the state of the iterator.
      Specified by:
        `next` in interface `SequenceIterator`
      Overrides:
        `next` in class `ItemMappingIterator`
      Returns:
        the next item, or null if there are no more items. Once a call on next() has returned null, no further calls should be made. The preferred action for an iterator if subsequent calls on next() are made is to return null again, and all implementations within Saxon follow this rule.
      Throws:
        `XPathException` - if an error occurs retrieving the next item

    - #### close

          public void close()

      The user of a `SequenceIterator` is encouraged to call the `close()` method if no further items are required from the sequence of items delivered by the `SequenceIterator`. This allows resources to be released. A `SequenceIterator` is NOT normally closed explicitly if it has been read to completion. This implementation of the `close()` method shuts down the `ExecutorService` used to schedule threads.
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `SequenceIterator`
      Overrides:
        `close` in class `ItemMappingIterator`