Threading 101: dont sleep while holding a lock
This commit is contained in:
parent
c5c80aaa57
commit
a4e8f36130
|
@ -299,19 +299,21 @@ public class DemoBox extends Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
long sleep_time = 1000;
|
||||||
while (renderThread != null) {
|
while (renderThread != null) {
|
||||||
|
|
||||||
// check for change of demo
|
// check for change of demo
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// if no demo set, just sleep
|
// if no demo set, just sleep
|
||||||
if (activeDemo == null) {
|
if (activeDemo == null) {
|
||||||
sleep(1000);
|
sleep_time = 1000;
|
||||||
} else {
|
} else {
|
||||||
// we have a demo!
|
// we have a demo!
|
||||||
sleep(16);
|
sleep_time = 16;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sleep(sleep_time);
|
||||||
}
|
}
|
||||||
System.out.println("dead");
|
System.out.println("dead");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue