Need a thread to run every two hours...

Posted on 2006-07-20
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...
Question by:arctanx
  • 2
LVL 86

Assisted Solution

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

Accepted Solution

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

Timer timer = new Timer();

where theTask is a class that extends TimerTask.

Author Comment

ID: 17150130
I was actually thinking that myself.

LVL 86

Expert Comment

ID: 17150136

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
@SBGen Method 3 35
AWS and Java and Rest - newbie question (Is this an authentication issue) 4 65
Problem to start Neon 20 82
JUnit 4 @Before and @BeforeClass differences 3 47
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

948 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

20 Experts available now in Live!

Get 1:1 Help Now