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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web services creation SOAP vs REST 5 57
factorial example 4 50
How to execute a Python program and gather return output in Java 2 41
What's wrong with this code? 4 28
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 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