Package net.spy.memcached.compat
Class SyncThread<T>
java.lang.Object
java.lang.Thread
net.spy.memcached.compat.SpyThread
net.spy.memcached.compat.SyncThread<T>
- All Implemented Interfaces:
Runnable
Thread that invokes a callable multiple times concurrently.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CyclicBarrier
private final CountDownLatch
private T
private Throwable
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionSyncThread
(CyclicBarrier b, Callable<T> c) Get a SyncThread that will call the given callable when the given barrier allows it past. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection
<SyncThread<T>> getCompletedThreads
(int num, Callable<T> callable) Get a collection of SyncThreads that all began as close to the same time as possible and have all completed.static <T> int
getDistinctResultCount
(int num, Callable<T> callable) Get the distinct result count for the given callable at the given concurrency.Get the result from the invocation.void
run()
Wait for the barrier, invoke the callable and capture the result or an exception.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
callable
-
barrier
-
latch
-
throwable
-
rv
-
-
Constructor Details
-
SyncThread
Get a SyncThread that will call the given callable when the given barrier allows it past.- Parameters:
b
- the barrierc
- the callable
-
-
Method Details
-
run
public void run()Wait for the barrier, invoke the callable and capture the result or an exception. -
getResult
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 executecallable
- the thing to call- Returns:
- the completed SyncThreads
- Throws:
InterruptedException
- if we're interrupted during join
-
getDistinctResultCount
Get the distinct result count for the given callable at the given concurrency.- Type Parameters:
T
- the type of the callable- Parameters:
num
- the concurrencycallable
- the callable to invoke- Returns:
- the number of distinct (by identity) results found
- Throws:
Throwable
- if an exception occurred in one of the invocations
-