You probably wanted to just make the thread sleep
, and that is the name of the method you needed to call.
You called Object#wait()
, which is a thread coordination method, and you used an explicit timeout on it (a rather short one). My guess is that NetBeans is warning you about that timeout because normally we use Object#wait
without a timeout, and if we use the timeout, we don't wait
in a loop.
Now, NetBeans will also warn you about using Thread.sleep()
in a loop because normally, if you want to schedule a repeated task (that is what you are doing), you will use a ScheduledExecutorService
. That service is able to serve a lot of different scheduled tasks around your application, all with a single thread. Writing Thread.sleep()
explicitly in a loop needlessly hogs a whole thread (a heavyweight system resource) to do nothing but sleep most of the time.