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
2
votes
1 answer

Moving JPanels using TimerTask

So I have set up a Java GUI like the one pictured below (apologies for horribly painted recreation): Layout for Java GUI All of the JPanels are equal size (not shown well in the drawing). What I'm trying to do is make it so that when I am doing…
Abbey S
  • 23
  • 2
2
votes
1 answer

When do serversocket.accept() throws an exception? [java]

I want to have a counter of how much incoming connections I have per second. That means, I have made a loop like this one: int incomingConnections; while(true) { try { Socket socket = serverSocket.accept(); incomingConnections++; }…
Asqiir
  • 607
  • 1
  • 8
  • 23
2
votes
1 answer

How to stop timer in a swing application

I wrote a little code to change the colours of a few buttons to stimulate a random sequence offlashing colours. i have set a timer to do this for me but i just dont know how to stop it Heres my code Timer timer = new Timer(100, new…
Claudiga
  • 427
  • 1
  • 4
  • 15
2
votes
1 answer

robolectric unit test android Timer

I'm writing unit tests for Android app, which code I shouldn't change. I've encountered a problem with testing a piece of code using java.util.Timer. I'm looking for a way to cause the task to execute immediately, without the need to wait till…
Piotr Śmietana
  • 393
  • 2
  • 19
2
votes
1 answer

Start and stop TimerTask in android

I have a dynamic viewpager which shows image, youtube video and soundcloud audio. I added timertask to auto-change viewpager pages every 3 seconds. I want to stop this auto-change when a youtube video is playing or a soundcloud audio is playing and…
Somnath Pal
  • 1,570
  • 4
  • 23
  • 42
2
votes
1 answer

TimerTask runs one more time after I call timer.cancel() method

TimerTask runs one more time after I call timer.cancel() method. I don't need TimerMethod to be executed after I call stopBusTimer() method. Can somebody explain why is it happening? busTimer = new Timer(); busTimer.schedule(new TimerTask() { …
Zhangali Bidaibekov
  • 591
  • 1
  • 7
  • 13
2
votes
2 answers

Android call method every 10 seconds with handler

I want to call my function every 10 seconds with a timer and my function has a handler it shows an error: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() My function: public void startData(){ …
Deidara
  • 667
  • 2
  • 13
  • 28
2
votes
1 answer

Performing a task everyday using TimerTask doesn't work for the next day.(with other problems)

I have a TimerTask that updates a few tables everyday at specific times(not one task per day, different tasks at different times in a day). I get a few time periods from a database and check if the current time is equal to one of the times in the…
Nobody
  • 73
  • 11
2
votes
1 answer

Schedule a TimerTask at specific time once per day in a service in android

I have a TimerTask object timerTask. My code is running but when service gets started initially, my timer task runs instantly before the specified time i.e. 3:30 PM, though I want it to run on 3:30 PM once per day only. Calendar cal =…
zeeali
  • 1,524
  • 20
  • 31
2
votes
2 answers

how can to stop timer task

I have a timer and timer task and handler and runnable my code be execute every 10 seconds until ServerResponse variable in not empty and then redirect to another activity. but when my code redirect to another activity timer task is working…
soheila
  • 87
  • 1
  • 1
  • 9
2
votes
2 answers

OnDestroy restarts service, how can I destroy my activity without killing or restarting the service?

I'm writting an app that pops up notifications from time to time. a service is running in the background, and when I kill the app the service is restarted and a notification pops up, but I don't want this to happen. I want the service to stay there…
2
votes
2 answers

Run timer without thread in java

I am building simulator that run 1000(and more) clients, in each client i want to run task after X time, i tried TimerTask, the problem is that in each task(more than 1000) new thread is created. Did there as any task timer without thread?
2
votes
2 answers

infinite loop vs boost::asio::deadline_timer C++ performance

I develop a server application that handles many connections from clients. Server sends message to each clients periodically(ex: every 1 second), check for client's expiry times(each client must be disconnected from the server forcibly when…
Ikarus
  • 1,169
  • 4
  • 14
  • 28
2
votes
0 answers

Multiple timer Task on same service conflicting and misbehaving

Since i have started using two timer task on same service it started misbehaving. As i am calling api in both timer task 1 is calling api after 30 seconds and another timertask is calling and api after 5 minutes. now they are misbehaving in the way…
Edward
  • 139
  • 3
  • 9
2
votes
1 answer

How can I reset a timer in java?

private void btnGuess1ActionPerformed(java.awt.event.ActionEvent evt) { Timer timer = new Timer(); TimerTask task = new TimerTask(){ private int i = 0; public void run(){ if (i <= 20){ …
Jeffrey Cao
  • 21
  • 2
  • 9