I was told that using Thread.Sleep()
is a bad solution, from time to time you need to make a certain time interval in the action loop in a synchronized method.
On the other hand, I have two different threads that are active for the duration of my program, as well as one common object, and when I use Object.wait (long) in this common object, it makes my GUI freeze for when something.
What would be the best solution for this problem?
Update This part of the code includes one of the threads that runs in the GUI:
class temperatureUp extends Thread { @Override public void run() { while(true) { try { GBC.increaseTemp(); updateSystemStatus(); } catch(Exception ex) { StringWriter w = new StringWriter(); ex.printStackTrace(new PrintWriter(w)); txtLog.setText(w + "\n" + txtLog.getText()); } } } };
and this is a synchronized method in a shared object, GBC:
public synchronized void increaseTemp() throws InterruptedException{
source share