Class ConcurrencyUtils


  • public class ConcurrencyUtils
    extends java.lang.Object
    Concurrency utilities.
    Author:
    Piotr Wendykier (piotr.wendykier@gmail.com), rstein - updates and code reformatting/removing obsolete code
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int extendDimension​(int x)  
      static int getNumberOfProcessors()
      Returns the number of available processors
      static int getNumberOfThreads()
      Returns the current number of threads.
      static boolean isForceThreads()  
      static boolean isPowerOf2​(int n)
      Checks if n is a power-of-two number
      static int nextExp2​(int n)  
      static int nextPow2​(int n)
      Returns the closest power of two greater than or equal to x.
      static int prevPow2​(int x)
      Returns the closest power of two less than or equal to x
      static void setForceThreads​(boolean forceThreads)  
      static void setNumberOfThreads​(int n)
      Sets the number of threads
      static void sleep​(long millis)
      Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
      static java.util.concurrent.Future<?> submit​(java.lang.Runnable task)
      Submits a Runnable task for execution and returns a Future representing that task.
      static <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> task)
      Submits a value-returning task for execution and returns a Future representing the pending results of the task.
      static void waitForCompletion​(java.util.concurrent.Future<?>[] futures)
      Waits for all threads to complete computation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • extendDimension

        public static int extendDimension​(int x)
      • getNumberOfProcessors

        public static int getNumberOfProcessors()
        Returns the number of available processors
        Returns:
        number of available processors
      • getNumberOfThreads

        public static int getNumberOfThreads()
        Returns the current number of threads.
        Returns:
        the current number of threads.
      • isForceThreads

        public static boolean isForceThreads()
        Returns:
        the forceThreads
      • isPowerOf2

        public static boolean isPowerOf2​(int n)
        Checks if n is a power-of-two number
        Parameters:
        n - input parameter
        Returns:
        true if n is power of 2
      • nextExp2

        public static int nextExp2​(int n)
      • nextPow2

        public static int nextPow2​(int n)
        Returns the closest power of two greater than or equal to x.
        Parameters:
        n - input parameter
        Returns:
        the closest power of two greater than or equal to x
      • prevPow2

        public static int prevPow2​(int x)
        Returns the closest power of two less than or equal to x
        Parameters:
        x - input parameter
        Returns:
        the closest power of two less then or equal to x
      • setForceThreads

        public static void setForceThreads​(boolean forceThreads)
        Parameters:
        forceThreads - the forceThreads to set
      • setNumberOfThreads

        public static void setNumberOfThreads​(int n)
        Sets the number of threads
        Parameters:
        n - number of requested threads
      • sleep

        public static void sleep​(long millis)
        Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
        Parameters:
        millis - sleep duration in [ms]
      • submit

        public static <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> task)
        Submits a value-returning task for execution and returns a Future representing the pending results of the task.
        Type Parameters:
        T - value type of callable
        Parameters:
        task - task for execution
        Returns:
        a handle to the task submitted for execution
      • submit

        public static java.util.concurrent.Future<?> submit​(java.lang.Runnable task)
        Submits a Runnable task for execution and returns a Future representing that task.
        Parameters:
        task - task for execution
        Returns:
        a handle to the task submitted for execution
      • waitForCompletion

        public static void waitForCompletion​(java.util.concurrent.Future<?>[] futures)
        Waits for all threads to complete computation.
        Parameters:
        futures - handles to running threads