I want to create a job queue to execute multiple tasks. but, my requirement is I should be able to add tasks to that job queue at any time and all those tasks should be executed sequentially. I searched for some solutions on the internet and found these two links:
But I can't use both of these solutions. Because after starting the ExecutorService I can't add a new task to the service. Because we know that It may throw InterruptedException or ConcurrentModificationException.
You can use a
BlockingQueueto keep waiting in a separate thread until one or moreRunnableshow up.