Package com.gengoai.concurrent
Class Threads
- java.lang.Object
-
- com.gengoai.concurrent.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 givenSystemInfo.NUMBER_OF_PROCESSORS
threads using a buffer of sizeSystemInfo.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 givennumberOfConsumerThreads
using a buffer of sizenumberOfConsumerThreads * 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 givennumberOfConsumerThreads
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 givenSystemInfo.NUMBER_OF_PROCESSORS
threads using a buffer of sizeSystemInfo.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 givennumberOfConsumerThreads
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 sleeptimeUnit
- 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 givenSystemInfo.NUMBER_OF_PROCESSORS
threads using a buffer of sizeSystemInfo.NUMBER_OF_PROCESSORS * 100
to feed the given consumer.- Type Parameters:
T
- the type of element being processed- Parameters:
iterator
- the items being processedconsumer
- 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 givennumberOfConsumerThreads
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 processedconsumer
- the consumer to process the items in the iteratornumberOfConsumerThreads
- the number of consumers to runbufferSize
- 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 givenSystemInfo.NUMBER_OF_PROCESSORS
threads using a buffer of sizeSystemInfo.NUMBER_OF_PROCESSORS * 100
to feed the given consumer.- Type Parameters:
T
- the type of element being processed- Parameters:
iterable
- the items being processedconsumer
- 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 givennumberOfConsumerThreads
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 processedconsumer
- the consumer to process the items in the iterablenumberOfConsumerThreads
- the number of consumers to runbufferSize
- 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 givennumberOfConsumerThreads
using a buffer of sizenumberOfConsumerThreads * 100
to feed the given consumer.- Type Parameters:
T
- the type of element being processed- Parameters:
iterable
- the items being processedconsumer
- the consumer to process the items in the iterablenumberOfConsumerThreads
- the number of consumers to run- Returns:
- True if the operation completed successfully
-
-