Questions tagged [timertask]

Timertask is a Java API class. Logically it represents a task that can be scheduled for one-time or repeated execution by a Timer

A TimerTask implements Runnable, also has a method to cancel the scheduled task, if required. It is used with java.util.Timer (Swing timer fires action events).

A concurrent package contains several classes that are similar to TimerTask by concept but provide additional funcitonality.

917 questions
9
votes
3 answers

timer.scheduleAtFixedRate does not stop when i call cancel

At onCreate, I run a task that repeats every minute. Here how I do it: myTimer = new Timer(); int delay = 30000; // delay for 30 sec. int period = 600000; // repeat every 60 sec. doThis = new TimerTask() { public void run() { …
Daler
  • 1,205
  • 3
  • 18
  • 39
9
votes
1 answer

java Timer TimerTask multiple threads

I'm using Timer and TimerTask to long poll for new messages for a chat application. I would like to examine two "slightly" different possibilities: 1 : Timer declared as local variable public List getLastMessages(...) { [...] …
Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
8
votes
1 answer

Using single Timer vs multiple Timers for scheduling TimerTasks in Android

I think I don't fully understand how the Timer and TimerTask work in Java and Android. Now, I have a number of periodic tasks defined, to be scheduled within a timer. I wonder should I use a single timer to schedule tasks, or using different timer…
Safa Kadir
  • 475
  • 1
  • 5
  • 18
8
votes
2 answers

Java: Scheduling a task in random intervals

I am quite new to Java and I'm trying to generate a task that will run every 5 to 10 seconds, so at any interval in the area between 5 to 10, including 10. I tried several things but nothing is working so far. My latest effort is below: timer= new…
idpolitis
  • 95
  • 1
  • 2
  • 8
8
votes
3 answers

How to stop a timer after certain number of times

Trying to use a Timer to do run this 4 times with intervals of 10 seconds each. I have tried stopping it with a loop, but it keeps crashing. Have tried using the schedule() with three parameters, but I didn't know where to implement a counter…
jimmyC
  • 563
  • 1
  • 6
  • 20
7
votes
5 answers

How to Pass Arguments to Timertask Run Method

I have a method and I want it to be scheduled for execution in later times. The scheduling time and method's arguments depend on user inputs. I already have tried Timers, but I have a question. How could It be possible to pass arguments to Java…
sjtaheri
  • 4,409
  • 3
  • 19
  • 15
7
votes
1 answer

Java Timer.schedule runs only once

I have a TiimerTask which should run based on a Timer.schedule. The problem is it only runs once when application starts... Maybe it's something pending, but I cannot understand what... this is my class which extends TimerTask public class…
MarioC
  • 2,934
  • 15
  • 59
  • 111
7
votes
2 answers

Which is the best method to excecute a task repeatedly in android ? (Eg :- Refreshing scores, Update Ui)

In android there are some options for refresh handling such as Timer, TimerTask, ScheduledExecutorService, AlarmManager & Handler. Which is the best method to do this. Did anyone checks the resource utilization of above mentioned methods?. I am…
Sujith
  • 7,543
  • 1
  • 28
  • 38
7
votes
2 answers

What should Timertask.scheduleAtFixedRate do if the clock changes?

We want to run a task every 1000 seconds (say). So we have timer.scheduleAtFixedRate(task, delay, interval); Mostly, this works fine. However, this is an embedded system and the user can change the real time clock. If they set it to a time in the…
The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
6
votes
1 answer

Timer Task VS Alarm Manager usage in Android Service

I need to fetch news/event updates from the server at regular intervals like for every 20mins in my Android App. AFAIK Intent Service and Broadcast Receiver combination will be better than using Service As I am not going to communicate with the…
Ganesh K
  • 2,623
  • 9
  • 51
  • 78
6
votes
2 answers

runOnUiThread(new Runnable() { punctuation (token) issue

Somehow it doesn't work, according to me it should be this: public void Splash(){ Timer timer= new Timer(); timer.schedule(new TimerTask(){ MexGame.this.runOnUiThread(new Runnable() { public void run(){ …
Diego
  • 4,011
  • 10
  • 50
  • 76
6
votes
1 answer

InputStream left open from TimerTask call to Guava map; GlassFish complains on undeploy

I'm implementing ServletContextListener in order to schedule various jobs on my app server (GlassFish 3.1). I'm using contextInitialized() to schedule recurring tasks, and contextDestroyed() to call cleanup methods, such as shutting down…
Paul Bellora
  • 54,340
  • 18
  • 130
  • 181
6
votes
2 answers

ImageView visibility Error with Timer

package name.cpr; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import java.util.Timer; import java.util.TimerTask; public class ExampleActivity extends ActionBarActivity { @Override protected…
5
votes
1 answer

Getting metadata from SHOUTcast using IcyStreamMeta

I am writing an app for Android that grabs meta data from SHOUTcast mp3 streams. I am using a pretty nifty class I found online that I slightly modified, but I am still having 2 problems. 1) I have to continuously ping the server to update the…
Karai17
  • 923
  • 2
  • 9
  • 26
5
votes
2 answers

Android: TimerTask scheduled for repetition getting fired only once

Ok this is a very weird problem I am having, and I'm pretty sure that I am messing up somewhere, but I can't quite figure out where. What I am trying is - Schedule a Timer to execute a TimerTask every five seconds The TimerTask in turn executes an…
curioustechizen
  • 10,572
  • 10
  • 61
  • 110
1 2
3
61 62