Recently I worked with ThreadPoolExecutor and priorityqueue and came across both methods future.cancel() on a future task. And task.remove() on the task it self, to remove it from the queue.
What is the better option? is there any difference? I can save list of both (the future object received from submit() or the tasks themselves), not sure what to use...
remove:
executor.remove(task);
executor.purge();
cancel:
futureObject.cancel(false);
I used the following: http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html#remove%28java.lang.Runnable%29
The false in the cancel is because I only want to remove a queue task, if it runs, let it finish.