/** * Created by Administrator on 2017/9/4. */ public class ResponsiveUI extends Thread { private static volatile double d = 1; public ResponsiveUI() { setDaemon(true); start(); } public void run() { while (true) { d = d + (Math.PI + Math.E) / d; } } public static void main(String[] args)throws Exception{ new ResponsiveUI(); System.in.read(); System.out.println(d); } }
把計算程序放在run()方法中,這樣它就能讓出處理器給別的程序。讓你按下「回車」鍵的時侯,能夠看到計算確實在做爲後臺程序運行,同時還在等待用戶輸入。io
輸出結果:class
再運行一次輸出結果:後臺