I have read some threads that said that calling Thread.sleep() in a loop is problematic and is a serious performance issue. But in some cases it seems the most natural thing to do.
For example if I want my application to do something every 3 minutes (lets say it's an autosave)
public void startAutosaveLoop(){
stop = false;
new Thread(new Runnable() {
@Override
public void run() {
while (!stop){
Thread.sleep(T*1000);
if (!stop){
// do something
}
}
}
}).start();
}
Is there a better way to doing this? Is this kind of situation problematic?