start()方法是用来启动线程,实现了多线程运行

点进去查看源码,发现start方法创建一个线程 并让线程处于就绪状态,并且在start方法内会调用start0()方法,而start0作为本地方法 会用c/c++创建一个线程并且调用run方法运行


private native void start0(); @Override public void run() {     if (target != null) {         target.run();     } } private void exit() {     if (group != null) {         group.threadTerminated(this);         group = null;     }     threadLocals = null;     inheritableThreadLocals = null;     inheritedAccessControlContext = null;     blocker = null;     uncaughtExceptionHandler = null; } public synchronized void start() {     if (threadStatus != 0)         throw new IllegalThreadStateException();     group.add(this);     boolean started = false;     try {         start0();         started = true;     } finally {         try {             if (!started) {                 group.threadStartFailed(this);             }         } catch (Throwable ignore) {             /* do nothing. If start0 threw a Throwable then               it will be passed up the call stack */         }     } }

而run 方法只是当成普通方法调用,程序还是主线程运行。

注:

Thread 的run方法是运行上一个线程

//而 THread 的start 的方法是创建一个线程并且运行

//尽量实现 runnable 接口 因为有线程池

最新文章

  1. ios 向工程里添加Fonts
  2. vtigerCRM5.4的安装和汉化 ubuntu
  3. swift 开眼今日精选
  4. zend studio一些常用配置
  5. 293. Flip Game
  6. 博弈论(SG函数):HNOI 2007 分裂游戏
  7. android之View的启动过程
  8. 【Sort】RadixSort基数排序
  9. CentOS7 开源跳板机(堡垒机) Jumpserver
  10. 第二章 js数据类型和变量
  11. Xmanager6 下载地址
  12. @EnableWebMvc,WebMvcConfigurationSupport,WebMvcConfigurer和WebMvcConfigurationAdapter区别
  13. Redis的使用及参考代码
  14. numpy中random的使用
  15. 【CentOS】JDK的安装
  16. noj装载问题
  17. 和嗲妹妹面试python,是种什么体验?
  18. sahrepoint 上传到文档库
  19. Codeforces 799D Field expansion - 搜索 - 贪心
  20. Linux crontab使用方法

热门文章

  1. 基于北斗gps设计的NTP网络时间服务器
  2. node 版本管理器 nvs
  3. java常用、通用代码或配置
  4. D - Pair of Topics
  5. Katalon-获取文本内容和预期文本对比(get Test)
  6. 读后笔记 -- Python 全栈测试开发 Chapter8:接口测试
  7. Redis缓存中的数据和数据库不一致
  8. D_GLIBCXX_USE_CXX11_ABI
  9. Linux 使用Nginx部署web项目
  10. 记录一次vue的报错