多线程

加锁  非原子操作

volatile  工作缓存副本

执行顺序
start开启后执行run方法  并行执行。
至于多个线程谁先执行,不确定。

串行执行和并行执行
一个object继承Thread后,多次start会抛异常,只有第一个start会被执行
如果直接执行这个对象的run方法,则是串行执行,如果在run方法里有一个while死循环,那么会出不来。主线程得不到执行。看不到主线程的打印

非常象德尔福以前代码 都是调start取执行run方法

查start方法,能看到它被执行两次会返回异常类型。
     * It is never legal to start a thread more than once.
     * @throws     IllegalThreadStateException  if the thread was already started.
     然后查run方法,可以看到它是一个Thread类的构造方法执行了start方法后,会call run方法
   * Causes this thread to begin execution; the Java Virtual Machine
     * calls the {@code run} method of this thread.

在run方法里有介绍。如果一个thread构造函数接受一个runable对象。那么runnable对象的run方法会被调
 * If this thread was constructed using a separate
     * {@code Runnable} run object, then that
     * {@code Runnable} object's {@code run} method is called;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值