Class SyncThread<T>

All Implemented Interfaces:
Runnable

public class SyncThread<T> extends SpyThread
Thread that invokes a callable multiple times concurrently.
  • Field Details

  • Constructor Details

    • SyncThread

      public SyncThread(CyclicBarrier b, Callable<T> c)
      Get a SyncThread that will call the given callable when the given barrier allows it past.
      Parameters:
      b - the barrier
      c - the callable
  • Method Details

    • run

      public void run()
      Wait for the barrier, invoke the callable and capture the result or an exception.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • getResult

      public T getResult() throws Throwable
      Get the result from the invocation.
      Returns:
      the result
      Throws:
      Throwable - if an error occurred when evaluating the callable
    • getCompletedThreads

      public static <T> Collection<SyncThread<T>> getCompletedThreads(int num, Callable<T> callable) throws InterruptedException
      Get a collection of SyncThreads that all began as close to the same time as possible and have all completed.
      Type Parameters:
      T - the result type of the SyncThread
      Parameters:
      num - the number of concurrent threads to execute
      callable - the thing to call
      Returns:
      the completed SyncThreads
      Throws:
      InterruptedException - if we're interrupted during join
    • getDistinctResultCount

      public static <T> int getDistinctResultCount(int num, Callable<T> callable) throws Throwable
      Get the distinct result count for the given callable at the given concurrency.
      Type Parameters:
      T - the type of the callable
      Parameters:
      num - the concurrency
      callable - the callable to invoke
      Returns:
      the number of distinct (by identity) results found
      Throws:
      Throwable - if an exception occurred in one of the invocations