Note that there are some explanatory texts on larger screens.

plurals
  1. POThread won't wake up
    primarykey
    data
    text
    <p>I'm trying to simulate a simple thermostat, using multi-threading. I have a desired temperature value saved on lblDesiredTemp and another label to display current temperature lblCurrentTemp. The problem occur when while there's more than two active thread in system. the threads which are waiting won't wake up!</p> <p>this is my method: <pre><code>'private synchronized void ApplySetting() { Thread tempetureUpdater = new Thread() { @Override public synchronized void run() { txtLog.setText(txtLog.getText() + "\n" + this.getName()); try { while(!isDone) this.wait(); } catch (InterruptedException ex) { txtLog.setText(txtLog.getText() + "\n" + ex.getMessage()); }</p> int Max = Integer.parseInt(lblDesiredTemp.getText()); int Current = Integer.parseInt(lblCurrentTemp.getText()); txtLog.setText(txtLog.getText() + "\n" + Current + " to " + Max); if(Current &gt; Max) { isDone = false; for (int i = Current; i &gt; Max; i--) { lblGasStatus.setText("Off"); try { Thread.sleep(3000); decreaseTemeture(); } catch (InterruptedException ex) { txtLog.setText(txtLog.getText() + "\n" + ex.getMessage()); } } txtLog.setText(txtLog.getText() + "\n" + this.getName() + " done!"); isDone = true; this.notifyAll(); } else { isDone = false; for (int i = Current; i &lt; Max; i++) { lblGasStatus.setText("On"); try { Thread.sleep(3000); increaseTemeture(); } catch (InterruptedException ex) { txtLog.setText(txtLog.getText() + "\n" + ex.getMessage()); } } txtLog.setText(txtLog.getText() + "\n" + this.getName() + " done!"); isDone = true; this.notifyAll(); } // Report the result using invokeLater(). SwingUtilities.invokeLater(new Runnable() { @Override public void run() { setEnabled(true); } }); } }; tempetureUpdater.start(); } </code></pre> <p>What's the problem?!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload