后台程序
2015-09-24 21:02
330 查看
package 后台程序; class DamonThread implements Runnable{ //实现Runnab接口 public void run(){ while(true){ System.out.println(Thread.currentThread().getName()+"--is running."); } } } public class 后台程序 { public static void main(String[] args) { System.out.println("main线程是后台程序吗?"+Thread.currentThread().isDaemon());//判断main方法是后台程序吗 DamonThread dt = new DamonThread(); //创建一个damonThread对象dt Thread t = new Thread(dt,"后台程序"); //创造一个线程对象t共享dt资源 System.out.println("t线程是默认程序吗?"+t.isDaemon()); //判断t是后台程序艾玛 t.setDaemon(true); //将t设置成后台程序 t.start(); for(int i = 0; i <100; i++) System.out.println(i); } } //只要有一个前台程序还在运行,程序就不会结束,换而言之,只要没有了前台程序,程序就终止了 //新创建的线默认是前台程序,可以通过setDaemon方法将其设置成后台程序
相关文章推荐
- Android Api Demos登顶之路(八十)Graphics-->PathFillTypes
- Cocos2d-x 手机游戏《疯狂的蝌蚪》资源 “开源” win32+安德鲁斯+iOS三合一
- Java基础知识强化70:正则表达式之引入案例(QQ号码校验)
- [sicily]1813. M进制数问题
- HDU - 1864 最大报销额(01背包)
- 汉诺塔
- More Effective C++ 条款20 协助完成"返回值优化(RVO)"
- 百度offe面经及找工作一个月体会
- TCP/IP的工作方式
- VMware10上CentOS6.5安装MySQL2.6.26
- THU数据结构编程作业一:查询范围(Range)
- (更新)OutputDebugString函数简单封装,实现格式化打印输出(VC++)
- POJ3984
- Android所遇到的问题归类
- 怎么给qt程序添加版本信息
- Redis 命令 - Hashs
- ServletContextListener
- PHP 执行系统外部命令 system() exec() passthru()
- 关于iOS国际化(根据手机App用户自己来切换语言) App支持多语言切换
- ubuntu中shell判断文件存在