首页 > 其他分享 >实现Runnable接口

实现Runnable接口

时间:2022-10-13 11:45:13浏览次数:58  
标签:Runnable TestThread3 实现 System 接口 int public

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("世界很大,欢迎回家");
        }
    }
}

标签:Runnable,TestThread3,实现,System,接口,int,public
From: https://www.cnblogs.com/qt0312/p/16787646.html

相关文章