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
4
votes
2 answers

Pausing timer without destroy and re-create - Android

I have this AsyncTask, that sleeps 0.1 second each time that executes "doInBackground", before that I was using a CountDownTimer to control my time. My problem is: I want to achieve a timer that can Pause without calling .cancel() and when starts…
guisantogui
  • 4,017
  • 9
  • 49
  • 93
4
votes
4 answers

Does everything scoped within TimerTask need to be thread safe?

Does everything scoped within TimerTask need to be thread safe? Example @Autowired private MySweetService mySweetService; int delaySeconds = 0; int intervalMinutes = 1; for(int i=0; i<5; i++) { Timer timer = new Timer(); …
stackoverflow
  • 18,348
  • 50
  • 129
  • 196
4
votes
4 answers

Two threads accessing same hashmap, one thread is continuously running other runs after 2 mins and clears that hashmap, how to handle this in java

The first thread is of JMS subscriber that listens to a topic. As soon as it gets a message it adds/updates/deletes entries in a hashmap. Another thread runs after every 2 mins using TimerClass and reads the contents of the same hashmap and stores…
Yamini
  • 73
  • 7
4
votes
2 answers

Throw exception in TimerTask to another method

I want to throw the following exception to another method, but I don't know how to achieve this correctly. public void startTimeoutHandler() throws TimeoutException { timer = new Timer(); timerTask = new TimerTask() { …
marc3l
  • 2,525
  • 7
  • 34
  • 62
4
votes
1 answer

Does TimerTask executing in new thread

Can I consider that code in run will be executed in new Thread or I must use AsyncTask? Timer myTimer = new Timer(); // Создаем таймер final Handler uiHandler = new Handler(); myTimer.schedule(new TimerTask() { // Определяем задачу …
Val
  • 4,225
  • 8
  • 36
  • 55
4
votes
4 answers

Need to fix my Java Timer code

Task - Turn a bulb on and off at a specified time during a day. I need to know how to fix my code as per the information given below. I also need to know if I am using the timer class correctly, that is, is my code design correct ? The code may work…
Time
  • 1,551
  • 2
  • 13
  • 14
4
votes
4 answers

Creating a Java Timer and a TimerTask?

I'm new to Java and I'm trying to set a simple timer, I'm familiar with set_interval, because of experience with JavaScript and ActionScript, I'm not so familiar with classes yet so I get confused easily, I understand that I need to set a new Timer,…
Radicate
  • 2,934
  • 6
  • 26
  • 35
4
votes
3 answers

Timer Task stops running after indefinite time in android

I am a newbie in android. I am developing an app in which a particular piece of code executes after every 5 seconds in background.To achieve this I am using a service with timer with a timer task in it. For sometime its working fine but after some…
user1508383
  • 95
  • 2
  • 11
4
votes
4 answers

Android Simple Timer/Timertask issue

I am trying to get a basic timer to work on Android and I have the following code in the onCreate() method: editText = (EditText) findViewById(R.id.edit_message); Timer time = new Timer(); time.schedule(new TimerTask() { …
James Andrew
  • 7,197
  • 14
  • 46
  • 62
4
votes
2 answers

java - Rescheduling a TimerTask for a game 'lobby'

Scenario: I am making a clone of a popular card game. There needs to be a period during which people can join the game. Sometimes, the period is too short. Therefore, I want to let people extend the waiting period. For the example numbers, the…
Riking
  • 2,389
  • 1
  • 24
  • 36
4
votes
1 answer

how to start a process in certain time in java?

i have one application which get the start and end time from the user and start the particular process at (start time) runs upto the (end time),for sample i use TimerTask utility in case it only start the process from the current time and runs…
Mr.Cool
  • 1,525
  • 10
  • 32
  • 51
3
votes
1 answer

What is the best way to schedule a task guaranteed to run at near-scheduled time in Android?

I have been using Timer & TimerTask with Pseudocode:- samplingTask = new TimerTask() { public void run() { collectSample(); } }; timer.schedule(samplingTask, 60*1000, 60*1000); //1 min This application is a long running app (e.g.…
Robin
  • 497
  • 5
  • 19
3
votes
4 answers

How can I prevent UI hang, when my service runs a TimerTask?

I have a service which contains a Timer and TimerTask for receiving data from Webservice in periods of time. When my TimerTask runs, the UI hangs until the Webservice process complete. How can I put my task in a thread to prevent the UI hanging? My…
Bob
  • 22,810
  • 38
  • 143
  • 225
3
votes
1 answer

java.util.Timer SystemTime effect?

Said now is 6 o'clock, I have a Timer and scheduled a TimerTask at 10 o'clock. After that, System DateTime is adjusted by an other service (ntp for example) to 9 o'clock. I still want my TimerTask will be fired at 10 o'clock but it does not, Timer…
secmask
  • 7,649
  • 5
  • 35
  • 52
3
votes
2 answers

Android - How to stop and pause timer

I have been running through alot of issues try to pause and unpause a timer, and if I lock the orientation to portrait or landscape it works, but thats not exactly what I want to do. Of course, the onCreate method is called when you change…
Shaun
  • 5,483
  • 10
  • 40
  • 49