欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

Java-多线程-Thread类-实现Runnable类

package cn.bruce.Thread;
//实现接口方式的线程
//创建Thread类对象,构造方法中,传递Runnable接口实现类
//调用Thread类的方法start()

public class RunnableDemo {
    public static void main(String[] args) {
        Runnabletest test = new Runnabletest();
        Thread t = new Thread(test);//需要将实现类传至Thread构造方法实现
        t.start();
        for (int i = 0; i < 10; i++)
        {
            System.out.println("main..."+i);
        }
    }
}

class Runnabletest implements Runnable {
    public void run() {
        for (int i = 0; i < 11; i++)
        {
            System.out.println("run..."+i);
        }
    }
}

 

posted @ 2020-08-27 14:12  萧静默  阅读(155)  评论(0编辑  收藏  举报