守护线程
2015-10-19 15:43
288 查看
package comm; class StopThread implements Runnable { public synchronized void run() { while (true) { try { wait(); } catch (InterruptedException e) { System.out.println(Thread.currentThread().getName() + "....exception"); } System.out.println(Thread.currentThread().getName() + "....run"); } } } public class StopThreadDemo { public static void main(String[] args) { StopThread st = new StopThread(); Thread t1 = new Thread(st); Thread t2 = new Thread(st); t1.setDaemon(true); //守护线程要在start之前设置, t2.setDaemon(true); t1.start(); t2.start(); int num = 0; while (true) { if (num++ == 10) { break; } System.out.println(Thread.currentThread().getName() + "------" + num); } } }
相关文章推荐
- iOS程序启动原理和UIApplication
- 去除空白cell的分割线
- 富文本Attributes详解
- 算法的前提条件
- C与OC、C++的区别
- Python scrapy run with Unhandled error in Deferred解决方案
- Android 设置页面 及 背景音乐 的实现
- exits和in的区别
- Java7中的switch...case支持string的实现细节
- tmux 基础教程
- 添加自动远程连接的脚本,自动输入密码,节省时间。
- OAF中下载附件之后页面失效,报浏览器后退异常
- shell 判断文件是否存在
- 4个常用的awk统计命令
- -rw-r--r-- 是什么意思?
- qemu-2.4.0.1编译问题
- 【PAT】1040. Longest Symmetric String (25)
- linux lsof详解
- MySQL运行状态show status中文详解
- C++Windows下创建多级目录