暂停线程意味着线程还能恢复运行

suspend()方法暂停线程。resume()恢复线程

测试如下

 package com.cky.thread;

 /**
* Created by edison on 2017/12/3.
*/
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() {
super.run();
while(true) {
i++;
}
}
}
 package com.cky.test;

 import com.cky.thread.MyThread;

 /**
* Created by edison on 2017/12/3.
*/
public class Test {
public static void main(String[] args) {
try {
MyThread myThread = new MyThread();
myThread.start();
Thread.sleep(5000); //A断
myThread.suspend();
System.out.println("A= "+ System.currentTimeMillis()+ " i="+myThread.getI());
Thread.sleep(5000);
System.out.println("A= "+ System.currentTimeMillis()+ " i="+myThread.getI()); //B段
myThread.resume();
Thread.sleep(5000); //c断
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();
} }
}
C:\itsoft\jdk\bin\java -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\itsoft\idea\IntelliJ IDEA 2016.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\itsoft\jdk\jre\lib\charsets.jar;C:\itsoft\jdk\jre\lib\deploy.jar;C:\itsoft\jdk\jre\lib\ext\access-bridge-32.jar;C:\itsoft\jdk\jre\lib\ext\cldrdata.jar;C:\itsoft\jdk\jre\lib\ext\dnsns.jar;C:\itsoft\jdk\jre\lib\ext\jaccess.jar;C:\itsoft\jdk\jre\lib\ext\jfxrt.jar;C:\itsoft\jdk\jre\lib\ext\localedata.jar;C:\itsoft\jdk\jre\lib\ext\nashorn.jar;C:\itsoft\jdk\jre\lib\ext\sunec.jar;C:\itsoft\jdk\jre\lib\ext\sunjce_provider.jar;C:\itsoft\jdk\jre\lib\ext\sunmscapi.jar;C:\itsoft\jdk\jre\lib\ext\sunpkcs11.jar;C:\itsoft\jdk\jre\lib\ext\zipfs.jar;C:\itsoft\jdk\jre\lib\javaws.jar;C:\itsoft\jdk\jre\lib\jce.jar;C:\itsoft\jdk\jre\lib\jfr.jar;C:\itsoft\jdk\jre\lib\jfxswt.jar;C:\itsoft\jdk\jre\lib\jsse.jar;C:\itsoft\jdk\jre\lib\management-agent.jar;C:\itsoft\jdk\jre\lib\plugin.jar;C:\itsoft\jdk\jre\lib\resources.jar;C:\itsoft\jdk\jre\lib\rt.jar;C:\多线程核心技术\第一章\out\production\第一章;C:\itsoft\idea\IntelliJ IDEA 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.cky.test.Test
A= 1512288685100 i=3391077327
A= 1512288690111 i=3391077327
B= 1512288695126 i=6819461694
B= 1512288700129 i=6819461694

结果分析

线程确实被暂停了,而且还可以恢复成运行的状态。

最新文章

  1. B树详解
  2. R入门<二>-时间序列研究
  3. delphi treeview 鼠标移动显示hint信息
  4. union all合并记录
  5. ByteBuffer常用方法详解
  6. struts之拦截器
  7. windows环境自动获取SVN仓库当前版本
  8. 再来写一个随机数解决方案,对Random再来一次封装
  9. sublime text如何保存为uft-8无bom编码格式文件
  10. Glog使用记录
  11. linux btrfs文件系统管理与应用
  12. A Bayesian Approach to Deep Neural Network Adaptation with Applications to Robust Automatic Speech Recognition
  13. WordPress中默认文本编辑器替换成百度UEditor编辑器
  14. 小程序点击按钮清空input
  15. java 调用windows的COM组件举例(使用JACOB)
  16. 【译】.NET Core 2.2 Preview 2 发布
  17. TOJ3448: 小学生的作业
  18. vba遗传算法之非一致性突变
  19. JS中图片飞飞效果
  20. 原生js实现拖动滑块验证

热门文章

  1. 克隆后没有IP
  2. select into tb_temp2 from tb_temp1 创建临时表实现上一个、下一个功能,使用完毕就删除临时表
  3. django rest framework restful 规范
  4. MySQL学习笔记-MySQL体系结构总览
  5. Tomcat的下载、安装、启动与关闭
  6. UML 类图几种关系的总结(图文并茂、案例详解)
  7. jmeter对需要登录的接口进行性能测测试
  8. java基本例子
  9. 华为QOS原理及配置
  10. Mac版Java安装与配置