Class EConfigure.ScheduledExecutor

  • Enclosing class:
    EConfigure

    public static final class EConfigure.ScheduledExecutor
    extends EConfigure.ThreadConfig
    eBus clients should consider using net.sf.eBus.client.EScheduledExecutor to 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 returned IETimer may be closed (canceling the timer) but does not contain a Future'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
    name Yes String NA Non-empty text representing unique dispatcher name.
    threadType Yes String NA Must be one of the following:
    • "blocking",
    • "spinning"
    • "spin+park", and
    • "spin+yield".
    priority No intThread.MIN_PRIORITY and ≤ Thread.MAX_PRIORITY EConfigure.DEFAULT_PRIORITY Defines scheduled executor thread priority.
    spinLimit Yes if threadType is either "spin+park" or "spin+yield".
    Otherwise not required and ignored if present.
    int ≥ zero NA Number of times scheduler thread spins waiting for timer to expire before yielding for parking.
    parkTime Yes if threadType is "spin+park" Duration ≥ zero NA Defines thread park time after reaching spin limit.

    Example scheduled executor configuration:

    name : "timer-1"
    threadType : "spin+park"
    priority : 8
    spinLimit : 2500000
    parkTime : 500 nanos
    

    Programmatic Scheduled Executor Configuration

    Scheduled executors may be created at run time using EConfigure.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);
    
    • Method Detail

      • threadType

        public final ThreadType threadType()
        Returns the thread type which defines how the thread operates
        Returns:
        thread operation type.