/**
 * 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()方法中,这样它就能让出处理器给别的程序。让你按下“回车”键的时侯,可以看到计算确实在作为后台程序运行,同时还在等待用户输入。

输出结果:

线程入门——创建有响应的用户界面

再运行一次输出结果:

线程入门——创建有响应的用户界面

 

转载于:https://my.oschina.net/u/560971/blog/1528499

相关文章:

  • 2022-02-08
  • 2021-09-15
  • 2022-12-23
  • 2021-11-03
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2021-08-29
  • 2022-01-03
  • 2021-04-15
相关资源
相似解决方案