线程的六种状态
1.新建状态
2.运行状态
3.堵塞状态
4.等待状态
5.休眠状态
6.死亡状态
public class Demo01 {
public static void main(String[] args) {
SubThread subThread = new SubThread();
subThread.start();
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread().getName()+"----"+i);
}
}
}
class SubThread extends Thread{
public void run() {
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread().getName()+"--"+i);
}
}
}
根据这段代码我们画一下 代码的执行顺序图
public class Demo01 {
public static void main(String[] args) {
SubThread subThread = new SubThread();
subThread.start();
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread().getName()+"----"+i);
}
}
}
class SubThread extends Thread{
public void run() {
for (int i = 0; i < 50; i++) {
System.out.println(Thread.currentThread().getName()+"--"+i);
}
}
}