1.8.1挂起线程(暂停线程)
来源:互联网 发布:软件维护是指 编辑:程序博客网 时间:2024/06/11 02:00
package demo;/** * Created by sunyifeng on 17/10/10. */public class MyThread extends Thread { private long i = 0; public long getI(){ return i; } public void setI(long i) { this.i = i; } @Override public void run(){ while (true) { i++; } }}
package demo;/** * Created by sunyifeng on 17/10/10. */public class Run { public static void main(String[] args) { try { MyThread myThread = new MyThread(); myThread.start(); Thread.sleep(5000); // 挂起 myThread.suspend(); System.out.println("A=" + System.currentTimeMillis() + ",i=" + myThread.getI()); Thread.sleep(5000); System.out.println("A=" + System.currentTimeMillis() + ",i=" + myThread.getI()); // 唤醒 myThread.resume(); Thread.sleep(5000); // 挂起 myThread.suspend(); System.out.println("B=" + System.currentTimeMillis() + ",i=" + myThread.getI()); Thread.sleep(5000); System.out.println("B=" + System.currentTimeMillis() + ",i=" + myThread.getI()); } catch (InterruptedException e) { e.printStackTrace(); } }}
运行结果:A=1507571201939,i=2244120410
A=1507571206943,i=2244120410
B=1507571211946,i=4650198636
B=1507571216950,i=4650198636
阅读全文
0 0
- 1.8.1挂起线程(暂停线程)
- linux中线程的挂起与恢复(进程暂停)
- linux中线程的挂起与恢复(进程暂停)
- linux中线程的挂起与恢复(进程暂停)
- (五)线程--管理线程(使线程中止,暂停,挂起等)
- c# winfrom 将当前线程挂起(暂停)指定的时间1秒
- linux中线程的挂起与恢复(进程暂停)(2013-06-19 13:42:58)
- 1.8.2挂起线程(独占锁)
- 1.8.3挂起线程(数据不同步)
- (七)线程--管理线程(使线程中止,暂停,挂起等)(示例下载)
- (七)线程--管理线程(使线程中止,暂停,挂起等)(示例下载)
- (七)线程--管理线程(使线程中止,暂停,挂起等)(示例下载)
- 暂停线程
- 线程并发库(创建线程、守护线程、暂停线程)
- java线程挂起(join)
- 当前程序暂停 & 线程暂停
- 根据Linux 线程挂起与唤醒原理,实现Sleep的暂停与继续
- 线程挂起与恢复
- 1.7.8停止线程(利用return)
- Meeting HDU
- RNNs in Tensorflow, a Practical Guide and Undocumented Features
- Centos7中安装jdk1.8
- Spring Cloud 学习记录及实践(1)-DS 服务注册中心
- 1.8.1挂起线程(暂停线程)
- Centos7中安装最新版maven3.5.0
- pypi传模块
- java并发编程--构造高效的结果缓存
- 17.10.10日报
- 1.8.2挂起线程(独占锁)
- The Next HDU
- 用Construct2编写小游戏
- redis-有序set集合