线程创建

package com.hqyj.api.threads;

public class TestDeom2 extends Thread {
public static void main(String[] args) {
Thread t1= new Thread(new TestDeom2());
t1.start();
//匿名内部类方式
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("7777");
}
}).start();

//lambda表达试
new Thread(()-> System.out.println("888")).start();
}

@Override
public void run() {
System.out.println("66");
}
}


方式2
public class TsetThread1  extends  Thread{
public static void main(String[] args) {
Thread t1= new TsetThread1();//1起始
t1.start();//2就绪


}

@Override//3运行
public void run() {
System.out.println(this.getName()+"run执行了");
} //4结束
}



posted @ 2022-04-25 19:58  java小寇  阅读(28)  评论(0)    收藏  举报