JacobKreynin JacobKreynin - 1 year ago 76
Java Question

Creating an interval in java

I need to run a function every 10 seconds in my java project.
I want it to be like an infinite loop yet without using while(true) or thread.sleep...

Any ideas?

Answer Source

This is more or less a duplicate of Making a Thread to Sleep for 30 minutes. That question mentions the ScheduledExecutorService, which I've used and been very happy with. It's a bit heavyweight, so Timer may be all that you need. The Java Tutorial has a decent example of how to use that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download