Threading 101: dont sleep while holding a lock

This commit is contained in:
Brian Matzon 2005-05-12 15:44:48 +00:00
parent c5c80aaa57
commit a4e8f36130
1 changed files with 4 additions and 2 deletions

View File

@ -299,19 +299,21 @@ public class DemoBox extends Frame {
}
public void run() {
long sleep_time = 1000;
while (renderThread != null) {
// check for change of demo
synchronized (this) {
// if no demo set, just sleep
if (activeDemo == null) {
sleep(1000);
sleep_time = 1000;
} else {
// we have a demo!
sleep(16);
sleep_time = 16;
repaint();
}
}
sleep(sleep_time);
}
System.out.println("dead");
}