A system library object that manages its own thread pool and can schedule actions to run on these threads (after a given delay or periodically).
Questions tagged [scheduledexecutorservice]
452 questions
151
votes
8 answers
scheduleAtFixedRate vs scheduleWithFixedDelay
What's the main difference between scheduleAtFixedRate and scheduleWithFixedDelay methods of ScheduledExecutorService?
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
…

Sawyer
- 15,581
- 27
- 88
- 124
107
votes
13 answers
How to run certain task every day at a particular time using ScheduledExecutorService?
I am trying to run a certain task everyday at 5 AM in the morning. So I decided to use ScheduledExecutorService for this but so far I have seen examples which shows how to run task every few minutes.
And I am not able to find any example which…

AKIWEB
- 19,008
- 67
- 180
- 294
104
votes
5 answers
How to run a background task in a servlet based web application?
I'm using Java and I want to keep a servlet continuously running in my application, but I'm not getting how to do it. My servlet has a method which gives counts of the user from a database on a daily basis as well as the total count of the users…

pritsag
- 1,193
- 3
- 10
- 13
78
votes
2 answers
How to remove a task from ScheduledExecutorService?
I have a ScheduledExecutorService that times a few different task periodically with scheduleAtFixedRate(Runnable, INIT_DELAY, ACTION_DELAY, TimeUnit.SECONDS);
I also have a different Runnable that I'm using with this scheduler.
the problem starts…

thepoosh
- 12,497
- 15
- 73
- 132
33
votes
2 answers
How do I schedule a task to run once?
I want to delay doing something, along the lines of setting a countdown timer that will "do a thing" after a certain amount of time.
I want the rest of my program to keep running while I wait, so I tried making my own Thread that contained a…

azurefrog
- 10,785
- 7
- 42
- 56
30
votes
4 answers
Thread.sleep() VS Executor.scheduleWithFixedDelay()
Goal: Execute certain code every once in a while.
Question: In terms of performance, is there a significant difference between:
while(true) {
execute();
Thread.sleep(10 * 1000);
}
and
executor.scheduleWithFixedDelay(runnableWithoutSleep, 0,…

rudgirello
- 303
- 1
- 3
- 5
27
votes
1 answer
Where do I create and use ScheduledThreadPoolExecutor, TimerTask, or Handler?
I need to make my RSS Feed reader check the feed every 10 minutes for new posts, and then parse them if there are new ones. I also need to update the UI about every minute.
I have read and heard different things from various sources. My current…

zr00
- 528
- 1
- 7
- 20
13
votes
4 answers
ScheduledExecutorService or ScheduledThreadPoolExecutor
I'm building an Android App which have to periodically do something in a Service. And I found that using ScheduledThreadPoolExecutor and ScheduledExecutorService is preferable to Timer.
Can anyone explain the difference between…

changbenny
- 378
- 6
- 17
13
votes
5 answers
Testing code which uses ScheduledExecutorService (without using Sleep)
I have a validation object which runs input through a series of checks. If an input fails any of the checks, the validation ends.
Inputs which pass all the checks get grouped based on a sliding time window. This window kicks off when the first piece…

Mark Cuban
- 307
- 1
- 2
- 7
13
votes
1 answer
ScheduledExecutorService and uncaught Error
A discussion in Code Review chat determined the following behaviour from a ScheduledExecutorService:
A task scheduled to run fails with a 'serious' problem, but there's no report, exception, or log of the problem. In other contexts, the application…

rolfl
- 17,539
- 7
- 42
- 76
12
votes
1 answer
How do I change the rate or period of a repeating task using ScheduledExecutorService?
I have a modified version of the bluetooth chat sample app. I have set up a ScheduledExecutorService which sends a command over bluetooth at a predefined rate using scheduleAtFixedRate.
I have set up a PreferenceActivity to allow the period to be…

greencardigan
- 393
- 1
- 3
- 13
10
votes
1 answer
Java "scheduleAtFixedRate" alternative solution?
I have a Java application that is used to communicate with an embedded device over a UART connection (RS422). The host queries the microcontroller for data in 5 millisecond intervals. Up until recently I've been using ScheduledExecutorService…

Ben
- 1,132
- 1
- 15
- 35
10
votes
2 answers
Java ScheduledExecutorService BAD Precision
Hi there I wrote a simple program to test the precision of the ScduledExecutorService.schedule() function.
The test sets a delay and checks the effective waited time.
The test have been performed on a i7 machine running Linux 3.8 x86_64, with both…

snovelli
- 5,804
- 2
- 37
- 50
9
votes
2 answers
Why is java ExecutorService newSingleThreadExecutor spawning two threads?
I have a sample java code below which if run as a console application behaves as I expected ( spawning a single thread to execute the runnable).
The strange behavior (spawning two threads - sample below) I see is when I run this sample as a service…

tint si
- 93
- 5
8
votes
1 answer
ScheduledExecutorService run only once inside Service
I am running ScheduledExecutorService inside of my service which takes image in background. ScheduledExecutorService running only once means taking only one picture after the interval passed in function. Showing no errors at all. Following is the…

Ahmed Nawaz
- 1,634
- 3
- 21
- 51