2015-04-20 15:36:01 -07:00
|
|
|
//: concurrency/ResponsiveUI.java
|
|
|
|
// User interface responsiveness.
|
2015-05-05 11:20:13 -07:00
|
|
|
// {TimeOutDuringTesting}
|
2015-04-20 15:36:01 -07:00
|
|
|
|
|
|
|
class UnresponsiveUI {
|
|
|
|
private volatile double d = 1;
|
|
|
|
public UnresponsiveUI() throws Exception {
|
|
|
|
while(d > 0)
|
|
|
|
d = d + (Math.PI + Math.E) / d;
|
|
|
|
System.in.read(); // Never gets here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ResponsiveUI extends Thread {
|
|
|
|
private static volatile double d = 1;
|
|
|
|
public ResponsiveUI() {
|
|
|
|
setDaemon(true);
|
|
|
|
start();
|
|
|
|
}
|
2015-05-05 11:20:13 -07:00
|
|
|
@Override
|
2015-04-20 15:36:01 -07:00
|
|
|
public void run() {
|
|
|
|
while(true) {
|
|
|
|
d = d + (Math.PI + Math.E) / d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
//! new UnresponsiveUI(); // Must kill this process
|
|
|
|
new ResponsiveUI();
|
|
|
|
System.in.read();
|
|
|
|
System.out.println(d); // Shows progress
|
|
|
|
}
|
|
|
|
} ///:~
|