线程的创建方式一:
1. 继承Thread类;
2.覆写run方法。
/*
继承Thread类
*/
class MyThread extends Thread
{
//覆写run方法
public void run()
{
System.out.println(Thread.currentThread().getName() + ".....run");
}
}
class TreadCreate1
{
public static void main(String[] args)
{
System.out.println(Thread.currentThread().getName() + ".....run");
//创建线程
MyThread t1 = new MyThread();
MyThread t2 = new MyThread();
MyThread t3 = new MyThread();
MyThread t4 = new MyThread();
//开启线程
t1.start();
t2.start();
t3.start();
t4.start();
}
}
多线程运行时栈内存图解