1.先看看jdk文档

 void    run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
 void    start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

线程调用run()方法是直接执行其run方法(正常情况)。

线程调用start()方法后进入准备状态,等待CPU的调度,当切换到该线程时,线程进入运行状态,执行run()方法。

既然都是执行线程的run方法,为什么不直接调用run方法?

2.再看代码

 public class Main {

     public static void main(String[] args) {
Mythread t = new Mythread();
Thread thread1 = new Thread(t);
Thread thread2 = new Thread(t);
System.out.println("begin = " + System.currentTimeMillis());
thread1.setName("我是线程1");
thread2.setName("我是线程2");
thread1.run();
thread2.start();
System.out.println("end = " + System.currentTimeMillis());
}
} class Mythread extends Thread{
public void run() {
try {
System.out.println("threadName: "+this.currentThread().getName()+" begin");
Thread.sleep(1000);
System.out.println("threadName: "+this.currentThread().getName()+" end");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

运行结果:

可以发现直接调用run方法时是被主线程当做普通的方法调用,并不是真正的多线程。

最新文章

  1. Quartz2D内存管理
  2. [Java入门笔记] Java语言基础(一):注释、标识符与关键字
  3. ROS下创建第一个节点工程
  4. Windows下配置使用WinPcap
  5. 关于TouchEvent中出现异常:MessageQueue-JNI问题
  6. vim 分屏 screen
  7. WCF - 绑定后续之自定义绑定
  8. IE9 "CSS 因 Mime 类型不匹配而被忽略“问题
  9. egret-android-support-gradle版
  10. JS学习之动态加载script和style样式
  11. https和http共存的nginx简单配置
  12. python '%r'或者'{!r}'的意思
  13. 服务管理之mysql基础
  14. python实现异步调用函数
  15. IDEA+'mvn' 不是内部或外部命令
  16. Day019--Python--反射
  17. Bootstrap Modal 使用remote从远程加载内容
  18. 解读 --- 基于微软企业商务应用平台 (Microsoft Dynamics 365) 之上的人工智能 (AI) 解决方案
  19. 028、HTML 标签3表单标签插入组件
  20. yarn 制作 npm 包

热门文章

  1. 撸基础篇系列,JAVA的NIO部分
  2. Android网络开发实例(基于抓包实现的网络模拟登录,登出和强制登出)
  3. Linux tomcat部署War包,Linux在Tomcat部署JavaWeb项目,Linux部署War包
  4. mfc--使用ShellExecute打开另一个可执行程序
  5. TP框架 基础1
  6. Maven转换成Eclipse项目后的依赖库更新问题
  7. Maven进阶宝典
  8. 简单聊聊TestNG中的并发
  9. 3101: N皇后
  10. JAVA I/O 字符输出流简要概括