Class Threads


  • public final class Threads
    extends Object
    Convenience methods for manipulating threads and processing data on multiple-threads
    Author:
    David B. Bracewell
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> boolean process​(Iterable<T> iterable, Consumer<T> consumer)
      Processes the given iterable across the given SystemInfo.NUMBER_OF_PROCESSORS threads using a buffer of size SystemInfo.NUMBER_OF_PROCESSORS * 100 to feed the given consumer.
      static <T> boolean process​(Iterable<T> iterable, Consumer<T> consumer, int numberOfConsumerThreads)
      Processes the given iterable across the given numberOfConsumerThreads using a buffer of size numberOfConsumerThreads * 100 to feed the given consumer.
      static <T> boolean process​(Iterable<T> iterable, Consumer<T> consumer, int numberOfConsumerThreads, int bufferSize)
      Processes the given iterable across the given numberOfConsumerThreads using a buffer of given size to feed the given consumer.
      static <T> boolean process​(Iterator<T> iterator, Consumer<T> consumer)
      Processes the given iterator across the given SystemInfo.NUMBER_OF_PROCESSORS threads using a buffer of size SystemInfo.NUMBER_OF_PROCESSORS * 100 to feed the given consumer.
      static <T> boolean process​(Iterator<T> iterator, Consumer<T> consumer, int numberOfConsumerThreads, int bufferSize)
      Processes the given iterator across the given numberOfConsumerThreads using a buffer of given size to feed the given consumer.
      static void sleep​(long milliseconds)
      Sleeps the thread suppressing any errors.
      static void sleep​(long time, TimeUnit timeUnit)
      Sleeps the thread suppressing any errors for a given time unit.
    • Method Detail

      • sleep

        public static void sleep​(long milliseconds)

        Sleeps the thread suppressing any errors.

        Parameters:
        milliseconds - The amount of time in milliseconds to sleep
      • sleep

        public static void sleep​(long time,
                                 TimeUnit timeUnit)

        Sleeps the thread suppressing any errors for a given time unit.

        Parameters:
        time - The amount of time to sleep
        timeUnit - The TimeUnit that the time is in
      • process

        public static <T> boolean process​(Iterator<T> iterator,
                                          Consumer<T> consumer)
        Processes the given iterator across the given SystemInfo.NUMBER_OF_PROCESSORS threads using a buffer of size SystemInfo.NUMBER_OF_PROCESSORS * 100 to feed the given consumer.
        Type Parameters:
        T - the type of element being processed
        Parameters:
        iterator - the items being processed
        consumer - the consumer to process the items in the iterator
        Returns:
        True if the operation completed successfully
      • process

        public static <T> boolean process​(Iterator<T> iterator,
                                          Consumer<T> consumer,
                                          int numberOfConsumerThreads,
                                          int bufferSize)
        Processes the given iterator across the given numberOfConsumerThreads using a buffer of given size to feed the given consumer.
        Type Parameters:
        T - the type of element being processed
        Parameters:
        iterator - the items being processed
        consumer - the consumer to process the items in the iterator
        numberOfConsumerThreads - the number of consumers to run
        bufferSize - the size of the buffer used for feeding the consumer threads
        Returns:
        True if the operation completed successfully
      • process

        public static <T> boolean process​(Iterable<T> iterable,
                                          Consumer<T> consumer)
        Processes the given iterable across the given SystemInfo.NUMBER_OF_PROCESSORS threads using a buffer of size SystemInfo.NUMBER_OF_PROCESSORS * 100 to feed the given consumer.
        Type Parameters:
        T - the type of element being processed
        Parameters:
        iterable - the items being processed
        consumer - the consumer to process the items in the iterable
        Returns:
        True if the operation completed successfully
      • process

        public static <T> boolean process​(Iterable<T> iterable,
                                          Consumer<T> consumer,
                                          int numberOfConsumerThreads,
                                          int bufferSize)
        Processes the given iterable across the given numberOfConsumerThreads using a buffer of given size to feed the given consumer.
        Type Parameters:
        T - the type of element being processed
        Parameters:
        iterable - the items being processed
        consumer - the consumer to process the items in the iterable
        numberOfConsumerThreads - the number of consumers to run
        bufferSize - the size of the buffer used for feeding the consumer threads
        Returns:
        True if the operation completed successfully
      • process

        public static <T> boolean process​(Iterable<T> iterable,
                                          Consumer<T> consumer,
                                          int numberOfConsumerThreads)
        Processes the given iterable across the given numberOfConsumerThreads using a buffer of size numberOfConsumerThreads * 100 to feed the given consumer.
        Type Parameters:
        T - the type of element being processed
        Parameters:
        iterable - the items being processed
        consumer - the consumer to process the items in the iterable
        numberOfConsumerThreads - the number of consumers to run
        Returns:
        True if the operation completed successfully