创建线程方法1,继承Thread类:
public class MYThread extends Thread{
//重写run方法
public void run() }
//创建线程对象,并开启线程
main(){
MyThread mt=new MyThread();
mt.start()
}
创建线程方法2:实现Runnable类:
public class MyRunnable implements Runnable{
public void run(){} }
//创建线程任务对象,创建线程对象并传递线程任务,开启线程
main(){
MyRunnable mr1=new MyRunnable()
MyRunnable mr2=new MyRunnable()
Thread t=new Thread(mr1) // Thread(mr2)
t.start()