Suppose I have a nametag, which is UI component in GUI program. The nametag will constantly change its text based on the data. If the user change his/her name data, then he/she will see the change in nametag. For this task, my code looks like this:
Thread thread = new Thread(new Ruable(){
@Override
public void run() {
while (true){
String name = data.getName();
nametag.setText(name);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
Since the reaction time of 0.1s seems instant to people, I included Thread.sleep(100) for computer to take a break. However, I am not sure if that helps the computer in terms of energy usage or something. Is sleep method in this case complete waste of time? No benefit at all?
