-
|
Thanks for your excellent work. I hava a little confusion about the design of
void scheduleAfterWrite() {
@Var int drainStatus = drainStatusOpaque();
for (;;) {
switch (drainStatus) {
case IDLE:
casDrainStatus(IDLE, REQUIRED);
scheduleDrainBuffers();
return;
case REQUIRED:
scheduleDrainBuffers();
return;
case PROCESSING_TO_IDLE:
if (casDrainStatus(PROCESSING_TO_IDLE, PROCESSING_TO_REQUIRED)) {
return;
}
drainStatus = drainStatusAcquire();
continue;
case PROCESSING_TO_REQUIRED:
return;
default:
throw new IllegalStateException("Invalid drain status: " + drainStatus);
}
}
}
void scheduleDrainBuffers() {
if (drainStatusOpaque() >= PROCESSING_TO_IDLE) {
return;
}
if (evictionLock.tryLock()) {
try {
int drainStatus = drainStatusOpaque();
if (drainStatus >= PROCESSING_TO_IDLE) {
return;
}
setDrainStatusRelease(PROCESSING_TO_IDLE);
executor.execute(drainBuffersTask);
} catch (Throwable t) {
logger.log(Level.WARNING, "Exception thrown when submitting maintenance task", t);
maintenance(/* ignored */ null);
} finally {
evictionLock.unlock();
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
A stronger memory ordering alone would not be enough as there would be races of multiple writes observing the We don't want to treat the |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for you reply. The scheduling principle of ForkJoinPool is too complicated, and I don't know much about it. What I don't understand is why returning false can ensure that each submitted task is attempted to be executed once? After writing the cache item, PerformCleanupTask will be submitted again. |
Beta Was this translation helpful? Give feedback.
ForkJoinTaskis a future so it has a concept of completion which the internaldoExec()method checks before it will callexec(). When returningfalsewe indicate that there is a reschedule strategy so that the task may be invoked again if re-submitted to the pool. In FJP's case this is primarily forCountedCompleterwhile In ours we want each submission of the task to try an execute once and never have the task instance be considered completed. This is because our usage is purely an optimization to avoid an allocatio…