OnJava8-Examples/concurrency/ResponsiveUI.java

34 lines
819 B
Java
Raw Normal View History

2015-06-15 17:47:35 -07:00
//: concurrency/ResponsiveUI.java
// <20>2015 MindView LLC: see Copyright.txt
// 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
}
} /* Output: (None) *///:~