I want to make my program sleep for 30 miutes or 1 hour . I can do that by using Thread.sleep() but is there any alternate way?

Recommended Answers

All 4 Replies

you could use a Timer.
or have a method like this:

public static void sleep(int milliSeconds){
  for ( int i = 0; i < milliSeconds; i++ ){}

this is just an example, not the most efficient way, and most likely an int is not the best type to use for this, but it can get you the idea.

but why not using the sleep method?

Just set a java.util.Timer to run your method after an initial delay of 30 minutes or whatever.

@stultuske: what are you smoking? Did you miss something out of that code, or was it pure Monty Python?

@JamesCherrill: no, just had gotten out of bed actually :)

That served my purpose..Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.