File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Thread.sleep in loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread.sleep in loop" Watch "Thread.sleep in loop" New topic

Thread.sleep in loop

Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 191

I just began using NetBeans 6.9 and it has new hints available to the programmer. One of my classes is a lowe level thread that sleep every 5 seconds after which it verifies the introduction of any USB memory devices into Windows. NetBeans hints to me that a sleep call with a while loop can be dicey, well not exactly in those words. The class functions correctly and there is no noticeable decline in performance of the program. I don't see any other way around the way I have cided the calss below:

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

You'll have to tell us what the message is, if you want some guesses as to what it means. As far as this code goes, nothing wrong with sleeping inside a loop.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Thread.sleep in loop
It's not a secret anymore!