java多线程学习二

//1,定义一个类实现Runnable

//2,重写run方法

//3,将要执行的代码写在run方法中

//4,创建Runnable的子类对象

//5,将其当作参数传递给Thread的构造函数

//6,开启线程

public class Appiumpage {

    public static void main(String[] args) {

        MyRunnerable mr = new MyRunnerable();
        Thread t = new Thread(mr);
        t.start();
        for (int i = 0; i < 10000; i++) {
            System.out.println("main()");
        }
    }

}

class MyRunnerable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println("runnerable()接口");
        }
    }
}

猜你喜欢

转载自blog.51cto.com/357712148/2156205