Class StreamContext


  • class StreamContext
    extends java.lang.Object
    This class controls stream execution mode (parallel/sequential), custom FJP and close handlers.

    Fields are package-private and mutable, but it's forbidden to change them from outside this class.

    For performance reasons shared objects SEQUENTIAL and PARALLEL are used: then have no custom FJP and no close handler. If custom FJP or close handler is requested for shared object, a new object is created, otherwise the current one is modified.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StreamContext​(boolean parallel)  
    • Field Detail

      • parallel

        boolean parallel
      • fjp

        java.util.concurrent.ForkJoinPool fjp
      • closeHandler

        java.lang.Runnable closeHandler
    • Constructor Detail

      • StreamContext

        private StreamContext​(boolean parallel)
    • Method Detail

      • terminate

        <T> T terminate​(java.util.function.Supplier<T> terminalOperation)
      • terminate

        <T,​U> T terminate​(U value,
                                java.util.function.Function<U,​T> terminalOperation)
      • parallel

        StreamContext parallel​(java.util.concurrent.ForkJoinPool fjp)
      • close

        void close()
      • compose

        static java.lang.Runnable compose​(java.lang.Runnable r1,
                                          java.lang.Runnable r2)
      • combine

        StreamContext combine​(java.util.stream.BaseStream<?,​?> other)
      • of

        static StreamContext of​(java.util.stream.BaseStream<?,​?> stream)