I have a single thread pool ExecutorService object. At some time in the future tasks are added to be done using the submit() method. My understanding is that submit will submit add the submitted Runnable to the end of the list of tasks to be done. However I have a situation where based on a boolean I may want to submit the runnable to the front of the tasks to be executed. I don't want this to affect the current task, just that the next task done will be the one I just gave it. An example method is reproduced below. How do I do this?
Thanks
private ExecutorService singleLoadPool = Executors.newSingleThreadExecutor();
public void submitTask(Runnable run, boolean doNow) {
if (doNow)
singleLoadPool.submitFront(run); // This is the method I'm looking for
else
singleLoadPool.submit(run);
}