|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread com.vodafone360.people.service.WorkerThread
public class WorkerThread
The worker thread is the main thread of execution within the People Client service. It is responsible for running engines via the EngineManager The WorkerThread remains active while there are engines with pending run times, becoming dormant otherwise The WorkerThread can be woken up when a request is issued or via an Alarm set to trigger an engine runtime update check It is extremely important that the WorkerThread does not become blocked.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static java.lang.String |
ALARM_WORKER_THREAD
Name of alarm for waking up worker thread |
private static int |
FORCE_PAUSE_MS
Period of time to put worker thread to sleep after it has run MAX_RUNS_WITHOUT_PAUSE times without any pause. |
private static long |
LOOP_SLEEP_TIME_MS
Small wait time before looping around the engines again |
private static int |
MAX_RUNS_WITHOUT_PAUSE
Maximum loop iterations before allowing the worker thread to sleep for a while to preserve battery. |
private EngineManager |
mEngineManager
Reference to the EngineManager . |
private Handler |
mHandler
Handler used so that threads can wake up the worker thread by
sending a message. |
private java.lang.Boolean |
mLoopOneMoreTime
Set to true when any of the engines run at least once. |
private boolean |
mShutdownThread
Set to true when the worker thread is about to stop running. |
private java.lang.Object |
mWakeLock
Object is used to control the worker thread. |
private static java.lang.String |
WORKER_THREAD_NAME
Worker thread is renamed to this string |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
protected |
WorkerThread(Handler handler)
|
Method Summary | |
---|---|
protected void |
close()
Shut down and join the running thread. |
void |
run()
Loop through all the engines until no more work can be done right now, then set an Alarm if more work is required. |
private void |
setWakeupTime(long nextRunTime)
Wake up the WorkerThread at the given time. |
private void |
threadLoopSleep()
Pause the thread between cycles to stop it overloading the device and possibly blocking the UI. |
protected boolean |
wakeUp()
Wake the worker thread. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ALARM_WORKER_THREAD
private static final java.lang.String WORKER_THREAD_NAME
private static final long LOOP_SLEEP_TIME_MS
private static final int MAX_RUNS_WITHOUT_PAUSE
private static final int FORCE_PAUSE_MS
MAX_RUNS_WITHOUT_PAUSE
times without any pause. TODO: Make this
stricter as the code base improves.
private final java.lang.Object mWakeLock
private EngineManager mEngineManager
EngineManager
.
private Handler mHandler
Handler
used so that threads can wake up the worker thread by
sending a message.
private java.lang.Boolean mLoopOneMoreTime
private boolean mShutdownThread
Constructor Detail |
---|
protected WorkerThread(Handler handler)
context
- Context Android Application Context.Method Detail |
---|
protected boolean wakeUp()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
private void threadLoopSleep()
private void setWakeupTime(long nextRunTime)
set
- TRUE sets the restart time, FALSE cancel any pending restarts.protected void close()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc