OnJava8-Examples/tasks/ResponsiveUI.java
2016-01-25 18:05:55 -08:00

37 lines
927 B
Java

// tasks/ResponsiveUI.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// User interface responsiveness
// {TimeOutDuringTesting}
class UnresponsiveUI {
private volatile double d = 1;
public UnresponsiveUI() throws Exception {
while(d > 0)
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();
}
@Override
public void run() {
while(true) {
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
}
}