Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need a thread to run every two hours...

Posted on 2006-07-20
4
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Assisted Solution

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

Accepted Solution

by:
kawas earned 200 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses

609 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