NewSingleThreadScheduledExecutor working if thread is already busy

My requirement is to make a service that continues to check the queue after a certain interval and process the items in the queue.

For the planning task after 10 seconds, I use:

ScheduledExecutorService schd = Executors.newSingleThreadScheduledExecutor();
schd.scheduleAtFixedRate(readQueueRunnable, 10, 10, TimeUnit.SECONDS);

My question involves the first time, there are a lot of elements in the queue, and my only thread starts processing the queue.

Even after 10 seconds, my first thread is still executing it.

So, if runnable is called again after 10 seconds, it will stop the previous executable thread and start a new one. Or it checks if the thread is running, and if it works, then it will skip to Runnable in this case.

+4
source share
1 answer

newSingleThreadScheduledExecutor(); , . , 1 .

10 , 10 , . , , , , , - .

, 10 runnable, .

. . Runnable, . , runnable, .

, , , Runnable .

10 .

- , , , .

" " , . , .


, 10- , scheduleWithFixedDelay

+8

Source: https://habr.com/ru/post/1524316/


All Articles