Class ConcurrentUtil
java.lang.Object
ca.spottedleaf.concurrentutil.util.ConcurrentUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbackoff()Non-exponential backoff algorithm to use in lightly contended areas.static longexponentiallyBackoffComplex(long counter) Backoff algorithm to use for a lock that can block other threads (i.e if another thread contending with this thread can be thrown off the scheduler).static longexponentiallyBackoffSimple(long counter) Backoff algorithm to use for a short held lock (i.e compareAndExchange operation).static StringgenericToString(Object object) static VarHandlegetArrayHandle(Class<?> type) static VarHandlegetStaticVarHandle(Class<?> lookIn, String fieldName, Class<?> fieldType) static VarHandlegetVarHandle(Class<?> lookIn, String fieldName, Class<?> fieldType) static longlinearLongBackoff(long counter, long scale, long max) Simple exponential backoff that will linearly increase the time per failure, according to the scale.static longlinearLongBackoffDeadline(long counter, long scale, long max, long deadline) Simple exponential backoff that will linearly increase the time per failure, according to the scale.static void
-
Constructor Details
-
ConcurrentUtil
public ConcurrentUtil()
-
-
Method Details
-
genericToString
-
rethrow
-
getVarHandle
-
getStaticVarHandle
-
backoff
public static void backoff()Non-exponential backoff algorithm to use in lightly contended areas.- See Also:
-
exponentiallyBackoffSimple
public static long exponentiallyBackoffSimple(long counter) Backoff algorithm to use for a short held lock (i.e compareAndExchange operation). Generally this should not be used when a thread can block another thread. Instead, useexponentiallyBackoffComplex(long).- Parameters:
counter- The current counter.- Returns:
- The counter plus 1.
- See Also:
-
exponentiallyBackoffComplex
public static long exponentiallyBackoffComplex(long counter) Backoff algorithm to use for a lock that can block other threads (i.e if another thread contending with this thread can be thrown off the scheduler). This lock should not be used for simple locks such as compareAndExchange.- Parameters:
counter- The current counter.- Returns:
- The next (if any) step in the backoff logic.
- See Also:
-
linearLongBackoff
public static long linearLongBackoff(long counter, long scale, long max) Simple exponential backoff that will linearly increase the time per failure, according to the scale.- Parameters:
counter- The current failure counter.scale- Time per failure, in ns.max- The maximum time to wait for, in ns.- Returns:
- The next counter.
-
linearLongBackoffDeadline
public static long linearLongBackoffDeadline(long counter, long scale, long max, long deadline) Simple exponential backoff that will linearly increase the time per failure, according to the scale.- Parameters:
counter- The current failure counter.scale- Time per failure, in ns.max- The maximum time to wait for, in ns.deadline- The deadline in ns. Deadline time source:System.nanoTime().- Returns:
- The next counter.
-
getArrayHandle
-