Package org.threadly.concurrent
Class UnfairExecutor.AtomicStripeGenerator
- java.lang.Object
-
- org.threadly.concurrent.UnfairExecutor.AtomicStripeGenerator
-
- All Implemented Interfaces:
UnfairExecutor.TaskStripeGenerator
- Enclosing class:
- UnfairExecutor
public static class UnfairExecutor.AtomicStripeGenerator extends java.lang.Object implements UnfairExecutor.TaskStripeGenerator
Stripe generator which will round robin distribute tasks to threads. Internally this uses aAtomicLong
, which means if lots of tasks are being submitted in parallel there can be a lot of compare and swap overhead compared toUnfairExecutor.TaskHashXorTimeStripeGenerator
.This class should not be constructed, instead it should be provided via the static function
instance()
.- Since:
- 4.5.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getStripe(java.lang.Runnable task)
Generate an identifier for the stripe to distribute the task on to.static UnfairExecutor.AtomicStripeGenerator
instance()
Provides an instance which can be provided into the constructor ofUnfairExecutor
.
-
-
-
Method Detail
-
instance
public static UnfairExecutor.AtomicStripeGenerator instance()
Provides an instance which can be provided into the constructor ofUnfairExecutor
.- Returns:
- A new AtomicStripeGenerator instance
-
getStripe
public long getStripe(java.lang.Runnable task)
Description copied from interface:UnfairExecutor.TaskStripeGenerator
Generate an identifier for the stripe to distribute the task on to.- Specified by:
getStripe
in interfaceUnfairExecutor.TaskStripeGenerator
- Parameters:
task
- Task which can be used for referencing in determining the stripe- Returns:
- Any positive or negative long value to represent the stripe
-
-