answersLogoWhite

0

How does one set a timer in Java?

Updated: 8/10/2023
User Avatar

Wiki User

10y ago

Best Answer

To create a timer you might try the java.util.Timer class.

Check out the following methods:

void schedule(TimerTask task, long delay, long period)

Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.

void scheduleAtFixedRate(TimerTask task, long delay, long period)

Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.

If you just want a one-time event you can still use a Timer instance and schedule a single TimerTask or just create a new Thread with anonymous Runnable class that sleeps for 3 minutes before doing something.

new Thread(new Runnable() {

public void run() {

try {

Thread.sleep(TimeUnit.MINUTES.toMillis(3));

// do stuff here

} catch (InterruptedException e) {

// handle interruption

}

}

}).start();

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

Setting a timer on the Java software platform requires a user to create a new timer object within the software. The timer needs to be set with the time frames the user requires, then the timer started.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How does one set a timer in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can one set up the timer on the Canon Powershot A470?

One can set up the timer on the Canon Powershot A470 by opening the user's manual, checking the index and finding the page that explains how to set up the timer. Follow the instructions on that page.


How is a computer off timer set?

with a home lamp timer


Define set in java?

A Java set is a collection of things that do not contain duplicate elements. Duplicates are prohibited from Java sets.


Where can i find an online 10 second timer?

I do not think that u can find a useful 10 second online timer. I am not sure what you would like to time, but just the request to a server will porbably take more than 10 seconds. You can maybe use a client side timer, that is, one that runs a program on your own computer, just a java script timer that runs on you web browser . That may be ok, but directly to look at a server side timer, software that runs on a remote web site, is not a good solution. Hard to say what you need the timer for. There are some java script links below that may be helpful. If you give more details about the application of the timer, maybe i can help you


How do you set timer?

You need to turn the timer handle hars in a clockwise motion


Can this be set to come on and off with a timer when I am gone?

Yes, this television can be set to turn on and off using the timer function. Just set the time in the menu.


How do you set the timer on a 1993 Honda Accord?

can someone help me i need to know how to set the timer on a 1993 Honda accord


Does the itouch have a sleep timer?

I think if you go to the clock setting and go to timer, you can set it to sleep the ipod when timer expires.


What can be set by a timer?

a microwave cooker


Should in ground pool filtration be on a timer?

Yes it is best to set filtration to a timer.


How to set java for openGL?

Java has no native support for OpenGL. While there are some third-party attempts, I have yet to hear of one which completely implements OpenGL.


How do you set the constant textarea in java?

we can set the value of constant text area in Java in swing by creating a object of Jframe