Solved

Need a thread to run every two hours...

Posted on 2006-07-20
4
198 Views
Last Modified: 2010-03-31
What is the best practice to use for this?

I need a Thread to do some work every two hours.

It will do the work, sleep, and wake up in two hours.

Again I need the best practice for this.

Should I use another Timer class, or just use Thread.sleep(7200) or 720000 or whatever it is...
0
Comment
Question by:arctanx
  • 2
4 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 25 total points
ID: 17149891
util.Timer would probably be best
0
 
LVL 13

Accepted Solution

by:
kawas earned 50 total points
ID: 17149984
The class that CEHJ is what I have used:

Timer timer = new Timer();
timer.scheduleAtFixedRate(theTask, YOUR_STARTING_TIME_AS_DATE, FREQUENCY_IN_MILLI);

where theTask is a class that extends TimerTask.
0
 
LVL 2

Author Comment

by:arctanx
ID: 17150130
I was actually thinking that myself.

thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17150136
:-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now