Package com.mckoi.database
Class DatabaseDispatcher
- java.lang.Object
-
- java.lang.Thread
-
- com.mckoi.database.DatabaseDispatcher
-
- All Implemented Interfaces:
java.lang.Runnable
class DatabaseDispatcher extends java.lang.Thread
This is the database system dispatcher thread. This is a thread that runs in the background servicing delayed events. This thread serves a number of purposes. It can be used to perform optimizations/clean ups in the background (similar to hotspot). It could be used to pause until sufficient information has been collected or there is a lull in work before it does a query in the background. For example, if a VIEW is invalidated because the underlying data changes, then we can wait until the data has finished updating, then perform the view query to update it correctly.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
DatabaseDispatcher.DatabaseEvent
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList
event_queue
private boolean
finished
private TransactionSystem
system
-
Constructor Summary
Constructors Constructor Description DatabaseDispatcher(TransactionSystem system)
NOTE: Constructing this object will start the thread.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.Object
createEvent(java.lang.Runnable runnable)
Creates an event object that is passed into 'addEventToDispatch' method to run the given Runnable method after the time has passed.(package private) void
finish()
Ends this dispatcher thread.(package private) void
postEvent(int time_to_wait, java.lang.Object event)
Adds a new event to be dispatched on the queue after 'time_to_wait' milliseconds has passed.void
run()
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
event_queue
private java.util.ArrayList event_queue
-
system
private TransactionSystem system
-
finished
private boolean finished
-
-
Constructor Detail
-
DatabaseDispatcher
DatabaseDispatcher(TransactionSystem system)
NOTE: Constructing this object will start the thread.
-
-
Method Detail
-
createEvent
java.lang.Object createEvent(java.lang.Runnable runnable)
Creates an event object that is passed into 'addEventToDispatch' method to run the given Runnable method after the time has passed.The event created here can be safely posted on the event queue as many times as you like. It's useful to create an event as a persistant object to service some event. Just post it on the dispatcher when you want it run!
-
postEvent
void postEvent(int time_to_wait, java.lang.Object event)
Adds a new event to be dispatched on the queue after 'time_to_wait' milliseconds has passed.
-
finish
void finish()
Ends this dispatcher thread.
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
-