simple.util.schedule
Class PulseScheduler

java.lang.Object
  extended by simple.util.schedule.Scheduler
      extended by simple.util.schedule.PulseScheduler

public class PulseScheduler
extends Scheduler

The PulseScheduler is a scheduler that is used when the time accuracy is not of great importance. This will ensure that the scheduled items can be dequeued in pulses.

The aim of this type of Scheduler is to allow a large number of items to be enqueued using a large number of threads. The fact that there is a large number of threads means that the Registry will issue a large number of interrupts to dequeuers. The aim of the PulseScheduler is to ensure that the number of thread interrupts issued is kept low.

It achives this by ensuring that threads that are enqueuing objects have timeouts that are rounded to the nearest pulse. The effect that this has is that many objects will be enqueued with the same timeout values. When an enqueue is invoked the Registry is looked up to see if there is a thread dequeuing that has a larger timeout, if the timeouts are rounded then the Registry will see that there are few threads that are dequeuing with larger timeout values an interrupt will not be issued.

Care should be taken when choosing this type of Scheduler, large performance decreases can be incurred if the problem does not fit with the PulseScheduler. For most problems the default Scheduler is a better choice. This has a default maximum timeout of one minute and a default pulse of one hundred ms.

Author:
Niall Gallagher

Nested Class Summary
 
Nested classes/interfaces inherited from class simple.util.schedule.Scheduler
Scheduler.Entry
 
Field Summary
protected static long DEFAULT_FREQ
          The default frequency with which times are rounded.
protected  long half
          This is just a simple operation saving variable.
protected  long pulse
          The frequency that this Scheduler uses.
 
Fields inherited from class simple.util.schedule.Scheduler
DEFAULT_MAX, max, queue, registry
 
Constructor Summary
PulseScheduler()
          This creates a PulseScheduler to schedule objects.
PulseScheduler(long max)
          This creates a PulseScheduler to schedule objects.
PulseScheduler(long max, long freq)
          This creates a PulseScheduler to schedule objects.
 
Method Summary
protected  void enqueue(Scheduler.Entry entry)
          This just adds some changes to the superclasses version of the enqueue method.
 
Methods inherited from class simple.util.schedule.Scheduler
currentTime, dequeue, enqueue, interrupt, register, sleep, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FREQ

protected static final long DEFAULT_FREQ
The default frequency with which times are rounded.

See Also:
Constant Field Values

pulse

protected long pulse
The frequency that this Scheduler uses.


half

protected long half
This is just a simple operation saving variable.

Constructor Detail

PulseScheduler

public PulseScheduler()
This creates a PulseScheduler to schedule objects. This type of Scheduler is used to keep the interrupt rate low for threads. The PulseScheduler keeps the interrupt rate low by rounding the timeouts that objects are scheduled for to the next pulse timeout.


PulseScheduler

public PulseScheduler(long max)
This creates a PulseScheduler to schedule objects. This type of Scheduler is used to keep the interrupt rate low for threads. The PulseScheduler keeps the interrupt rate low by rounding the timeouts that objects are scheduled for to the next pulse timeout.

Parameters:
max - this is the maximum timeout that an object can have

PulseScheduler

public PulseScheduler(long max,
                      long freq)
This creates a PulseScheduler to schedule objects. This type of Scheduler is used to keep the interrupt rate low for threads. The PulseScheduler keeps the interrupt rate low by rounding the timeouts that objects are scheduled for to the next pulse timeout.

Parameters:
freq - this is the frequency of the pulses for this Scheduler
max - this is the maximum timeout that an object can have
Method Detail

enqueue

protected void enqueue(Scheduler.Entry entry)
This just adds some changes to the superclasses version of the enqueue method. This will ensure that the timeout of the entry is rounded to the nearest pulse. This keeps the interrupts low.

Overrides:
enqueue in class Scheduler
Parameters:
entry - this is the entry object that is being scheduled