-8

Is there any delay function in java like we have delay(milliseconds) in C language . If yes , can anyone please help me out with it's syntax ???

3 Answers3

1

You can do:

Thread.sleep(milliseconds);

OR

TimeUnit.MILLISECONDS.sleep(insertHere)

You can look at http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#sleep(long) and http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html

3751_Creator
  • 656
  • 2
  • 8
  • 22
0

Here's the API documentation for Thread.sleep: http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#sleep%28long%29

oschlueter
  • 2,596
  • 1
  • 23
  • 46
0

Yes you can use Thread.sleep. See Sleep for more information. It might be worthwhile thinking about what you are trying to archive here? Why do you want to pause execution? Do you have race conditions? Are you waiting on IO? There may be better ways to deal with this problem that pausing execution. Can you expand further?

Mark Butler
  • 466
  • 3
  • 10
  • Basically , I just want to see the exact process of looping . If it delay after each loop then it could help in the tracing ... – user3426628 Mar 16 '14 at 20:14
  • Ok makes sense. You could add a breakpoint if you are using and IDE then you would be able to follow the code line by line. BTW - please accept my answer if you are happy otherwise I will help you further. – Mark Butler Mar 16 '14 at 20:56