加锁 非原子操作
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;