实现Runnable接口

package demo1;

//创建线程方法2:实现Runnable接口,重写run方法,执行线程需要丢入Runnable接口实现类,调用start方法
public class TestThread3 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("The world is splendid, welcome home");
        }
    }

    public static void main(String[] args) {
        TestThread3 testThread3 = new TestThread3();
        Thread thread = new Thread(testThread3,"fast");//代理
        thread.start();

        for (int i = 0; i < 2000; i++) {
            System.out.println("世界很大,欢迎回家");
        }
    }
}

posted @ 2022-10-13 11:36  北极有熊ovo  阅读(58)  评论(0)    收藏  举报