Java timer example

Posted on 2007-10-02
Medium Priority
Last Modified: 2013-12-22
Hi Experts,

I need to have a timer that fires up an event when the specified time is elapsed. How can I do this.   Please provide a simple example.

Question by:ambuli
  • 2
LVL 86

Accepted Solution

CEHJ earned 600 total points
ID: 20000622
LVL 92

Assisted Solution

objects earned 400 total points
ID: 20002756
LVL 86

Expert Comment

ID: 20004322

Expert Comment

ID: 20430400
The following will start the task after a one-second delay.
new java.util.Timer().schedule(new java.util.TimerTask(){
  public void run(){
    /* your task here */
}, 1000);

Open in new window


Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 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