I am using ScheduledExecutorService to perform a task that invokes a fixed speed service. A service may return some data to a task. The task stores data in a queue. Some other threads are slowly picking items from the queue.
import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class EverlastingThread implements Runnable { private ScheduledExecutorService executorService; private int time; private TimeUnit timeUnit; private BlockingQueue<String> queue = new LinkedBlockingQueue<String>(500); public EverlastingThread(ScheduledExecutorService executorService, int time, TimeUnit timeUnit) { this.executorService = executorService; this.time = time; this.timeUnit = timeUnit; } public void run() {
How to suspend the executorService service until the queue filled with the task is cleared.
java scheduled-tasks executor
artfullyContrived
source share