Package org.threadly.concurrent.future
Enum ListenableFuture.ListenerOptimizationStrategy
- java.lang.Object
-
- java.lang.Enum<ListenableFuture.ListenerOptimizationStrategy>
-
- org.threadly.concurrent.future.ListenableFuture.ListenerOptimizationStrategy
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<ListenableFuture.ListenerOptimizationStrategy>
- Enclosing interface:
- ListenableFuture<T>
public static enum ListenableFuture.ListenerOptimizationStrategy extends java.lang.Enum<ListenableFuture.ListenerOptimizationStrategy>
Strategy to use for optimizing listener execution. By default no optimization will take place, but in certain use cases this optimization can significantly improve performance. For listeners which have fast / simple work loads, but which require a specific executor for thread safety, this can provide hints when the listener can be executed either in the calling thread or in a single threaded manner. By allowing these types of executions the listener does not need to re-queue on the executor. Allowing it to both skip the queue if the executor is backed up, but also reducing the amount of cross thread communication.- Since:
- 5.10
-
-
Enum Constant Summary
Enum Constants Enum Constant Description InvokingThreadIfDone
If the future has already completed, this optimization will ignore the executor passed in and will instead invoke the listener / callback on the invoking thread trying to add the listener.None
The default strategy, no optimization is assumed.SingleThreadIfExecutorMatch
This will optimize away the executor if the executor provided is the same one that the task WILL complete on.SingleThreadIfExecutorMatchOrDone
Similar toSingleThreadIfExecutorMatch
this will optimize away the executor if it will complete on the same executor provided.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ListenableFuture.ListenerOptimizationStrategy
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static ListenableFuture.ListenerOptimizationStrategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
None
public static final ListenableFuture.ListenerOptimizationStrategy None
The default strategy, no optimization is assumed. This is safest because listeners may block or otherwise require the executor to be provided to always be respected.
-
InvokingThreadIfDone
public static final ListenableFuture.ListenerOptimizationStrategy InvokingThreadIfDone
If the future has already completed, this optimization will ignore the executor passed in and will instead invoke the listener / callback on the invoking thread trying to add the listener. This is similar toSingleThreadIfExecutorMatchOrDone
except that it will still execute out on the executor if they match (which facilitates cases where concurrency of multiple threads on the same pool is desired).
-
SingleThreadIfExecutorMatch
public static final ListenableFuture.ListenerOptimizationStrategy SingleThreadIfExecutorMatch
This will optimize away the executor if the executor provided is the same one that the task WILL complete on. If the task is already completed then it is assumed that execution can NOT occur on the calling thread. If the calling thread can allow execution please seeSingleThreadIfExecutorMatchOrDone
.
-
SingleThreadIfExecutorMatchOrDone
public static final ListenableFuture.ListenerOptimizationStrategy SingleThreadIfExecutorMatchOrDone
Similar toSingleThreadIfExecutorMatch
this will optimize away the executor if it will complete on the same executor provided. But this also adds the optimization that if the future is complete, it is assumed that it can now execute in the calling thread. This is typically useful if you are adding a callback on a thread that is also executing on the executor you are providing.
-
-
Method Detail
-
values
public static ListenableFuture.ListenerOptimizationStrategy[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ListenableFuture.ListenerOptimizationStrategy c : ListenableFuture.ListenerOptimizationStrategy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ListenableFuture.ListenerOptimizationStrategy valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
-