[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [dsdp-dd-dev] DSF Executor & Runnable
|
In DSF documentation it says : *For DSF, the main rule for executors is
that they have to use a single thread to execute the runnable and that
the runnables be executed in the order that they were submitted.
*So if runnables are executed in the order that they were submitted;
in "DataGeneratorWithExecutor" sample, why *if
(fServiceQueueInProgress)* control is used ? I understood that
DsfRunnables will be executed orderly and there will be only one active
serviceQueue function. And there will be always one request in the queue ?
public void getCount(final DataRequestMonitor<Integer> rm) {
try {
fExecutor.execute( new DsfRunnable() {
public void run() {
fQueue.add(new CountRequest(rm));
serviceQueue();
}
});
} catch (RejectedExecutionException e) {
rm.setStatus(new Status(IStatus.ERROR,
DsfExamplesPlugin.PLUGIN_ID, "Supplier shut down"));
rm.done();
}
}
private void serviceQueue() {
// If a queue servicing is already scheduled, do nothing.
if (fServiceQueueInProgress) {
return;
}
if (fQueue.size() != 0) {
// If there are requests to service, remove one from the queue and
// schedule a runnable to process the request after a processing
// delay.
fServiceQueueInProgress = true;
final Request request = fQueue.remove(0);
fExecutor.schedule(
new DsfRunnable() {
public void run() {
if (request instanceof CountRequest) {
processCountRequest((CountRequest)request);
} else if (request instanceof ItemRequest) {
processItemRequest((ItemRequest)request);
}
// Reset the processing flag and process next
// request.
fServiceQueueInProgress = false;
serviceQueue();
}
},
PROCESSING_DELAY, TimeUnit.MILLISECONDS);
}
}