Search code examples
javathreadpoolexecutor

Java scheduled threadpool executor internal queue


I want to write a program that runs every 30 minutes. I am using java scheduled threadpool executor to process the tasks that i submit to the executor.

I have been looking at what the official docs say https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

and i have run into a dilemma.

Lets say i have submitted 5 tasks to the queue and i have defined 10 threads in the thread pool.

  1. Is there a likelyhood that one of the tasks shall be performed twice

  2. Does the threadpool executor make sure that a task is removed when it has been processed by one of the threads or must i remove the task myself once it has been processed.

Having the task removed is desirable since i wouldn't like old tasks to still be in the queue 30 minutes later.


Solution

  • It will be executed only once, the executor will remove it automatically.

    This is not explicitly documented, while the doc implys it:

    Executes the given task sometime in the future.