Package net.sf.eBus.config
Class EConfigure.ScheduledExecutor
- java.lang.Object
-
- net.sf.eBus.config.EConfigure.ThreadConfig
-
- net.sf.eBus.config.EConfigure.ScheduledExecutor
-
- Enclosing class:
- EConfigure
public static final class EConfigure.ScheduledExecutor extends EConfigure.ThreadConfig
eBus clients should consider usingnet.sf.eBus.client.EScheduledExecutorto perform timed tasks since expired tasks are posted to the client's dispatcher. This means the client remains effectively single threaded since messages are delivered to the client on its dispatcher.eBus scheduled executor is similar to but not the same as
java.util.concurrent.ScheduledExecutorService. The returnedIETimermay be closed (canceling the timer) but does not contain aFuture's computed result.Creating eBus Scheduled Executors
An application may create scheduled executors with a given unique name and JSON properties listed below.
Dispatcher JSON Properties Property Required? Type Default Description nameYes StringNA Non-empty text representing unique dispatcher name. threadTypeYes StringNA Must be one of the following: - "blocking",
- "spinning"
- "spin+park", and
- "spin+yield".
priorityNo int≥Thread.MIN_PRIORITYand ≤Thread.MAX_PRIORITYEConfigure.DEFAULT_PRIORITYDefines scheduled executor thread priority. spinLimitYes if threadTypeis either "spin+park" or "spin+yield".
Otherwise not required and ignored if present.int≥ zeroNA Number of times scheduler thread spins waiting for timer to expire before yielding for parking. parkTimeYes if threadTypeis "spin+park"Duration≥ zeroNA Defines thread park time after reaching spin limit. Example scheduled executor configuration:
name : "timer-1" threadType : "spin+park" priority : 8 spinLimit : 2500000 parkTime : 500 nanosProgrammatic Scheduled Executor Configuration
Scheduled executors may be created at run time usingEConfigure.ScheduledExecutorBuilder. The following example creates a scheduled executor using spin+park to wait for a timer to expire after so many checks and then parks the thread for given amount of time before checking again for expired timers:import java.time.Duration; import net.sf.eBus.config.EConfigure; import net.sf.eBus.config.EConfigure.ScheduledExecutor; import import net.sf.eBus.config.EConfigure.ScheduledExecutorBuilder; final ScheduledExecutorBuilder builder = EConfigure.scheduledExecutorBuilder(); final ScheduledExecutor config = builder.name("FastTimer") .threadType(ThreadType.SPINPARK) .priority(8) .spinLimit(2_500_000) .parkTime(Duration.ofNanos(500L) .build(); final EScheduledExecutor executor = EScheduledExecutor.newScheduledExecutor(config);
-
-
Field Summary
-
Fields inherited from class net.sf.eBus.config.EConfigure.ThreadConfig
mName, mParkTime, mPriority, mSpinLimit, mThreadType
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadTypethreadType()Returns the thread type which defines how the thread operatesStringtoString()
-
-
-
Method Detail
-
threadType
public final ThreadType threadType()
Returns the thread type which defines how the thread operates- Returns:
- thread operation type.
-
-