public class OnRequestUpdater extends Thread
OnRequestUpdater.Refreshable
interface.
Its main author is Albert Cardona, and I transcribe here a mail where he explained to me (JYT) the concept of the updater:
The logic is the following:
The thread has an infinite loop in its run method, so that it never dies (until its interrupted flag is set).
In that infinite loop, at each iteration we grab, under synchronization, the field "request", and store its value in the local variable "r".
The field request contains accumulated petitions for calling the function "refreshable.refresh()".
If "r" is larger than zero, it means: there was at least one request, so we execute the "refreshable.refresh()".
Then, again under synchronization, after having called "refreshable.refresh()", if and only if the field "request" still has the same value (i.e. there weren't any calls to "doUpdate()" while "refreshable.refresh()" was executing), we set the requests to 0, since no matter how many requests there are, only one invocation of "refreshable.refresh()" occurs. And we wait for a new notify().
What the "wait()" call does is: it frees the synchronization block, so that other threads can enter it, and also blocks execution. Then, any thread that calls "doUpdate()", will be able to enter the synchronization block, increment the request field, and call "notify()". The latter, all it does is to make any threads that are waiting on that same synchronization object ("this" in this case) to resume execution.
So the loop starts again.
What is accomplishes with this setup the "refreshable.refresh()" is not called once for every call to doUpdate(), but likely much less times: only as many as can be executed (and need be executed), and not more.
In a later mail, Johannes Schindelin explained to me that this solution was not optimal, and that for general heavy use refreshing, another solution must be sought. In the meantime, it is recommended that this class is used for simple purpose.
Modifier and Type | Class and Description |
---|---|
static interface |
OnRequestUpdater.Refreshable |
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
OnRequestUpdater(OnRequestUpdater.Refreshable refreshable)
Constructor autostarts thread
|
Modifier and Type | Method and Description |
---|---|
void |
doUpdate() |
void |
quit() |
void |
run() |
activeCount, checkAccess, clone, 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
public OnRequestUpdater(OnRequestUpdater.Refreshable refreshable)
Copyright © 2015–2021 Fiji. All rights reserved.