<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Busy waiting - Page 5 - Wikipedia">
<p>
<a accesskey="1" href="page.php?w=busy_waiting&amp;p=4">1.Previous</a><br />
<a accesskey="3" href="page.php?w=busy_waiting&amp;p=6">3.Next</a>
</p>
<p>static void main(String[] args) throws InterruptedException {        // Thread f1: waits for i to change from 0        Thread t1 = new Thread(() -> {            int local;            while ((local = i.get()) == 0) {                // Busy-wait (spinlock)            }            System.out.printf("i's value has changed to %d.%n", local);        });</p>

<p>        // Thread f2: changes i after 10 seconds        Thread t2 = new Thread(() -> {            int local = 99;            try {                Thread.sleep(10_000); // sleep 10 seconds  </p><p>
<a accesskey="1" href="page.php?w=busy_waiting&amp;p=4">1.Previous</a><br />
<a accesskey="3" href="page.php?w=busy_waiting&amp;p=6">3.Next</a>
</p>

<do type="prev" label="Search">
        <go href="search.wml"/>
</do>

</card>
</wml>
