Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Threads
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Threads and Synchronization
Pause a timer
Leroy Lemon
Greenhorn
Posts: 21
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello,
I have an app that is using at timer to run 2 tasks sequentially every 10 mins.
My question is, how would I tell the timer to pause for a short time before running the second task.
Here is my code.
public class Main { public Main() { try { timer = new Timer(); timer.schedule(new CSATask(),0,//initial delay 10*60000); //subsequent rate10*60000 = 10 minutes } catch (Exception e) { e.printStackTrace(); } } class CSATask extends TimerTask { public void run() { try { doMessages(); // insert pause here doQueries(); } catch (Exception e) { e.printStackTrace(); } finally { if (TraceLog.isRunning()) TraceLog.stop(); } } } public static void main(String args[]) { new Main(); } }
Satish Chilukuri
Ranch Hand
Posts: 266
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can use Thread.sleep()
try { doMessages(); Thread.sleep(pauseDuration); doQueries(); } catch (Exception e) { e.printStackTrace(); }
Leroy Lemon
Greenhorn
Posts: 21
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Works like a charm.
Thanks.
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Timer starts twice when it should start only once
Timer starts twice when it should start only once
Java Threads: wait+notify
How to Kill a running thread
Problem of using Pipe in threads
More...