4月11日,MyThread,每日20行。

来源:互联网 发布:新歌2016网络红歌 编辑:程序博客网 时间:2024/06/07 07:46
public class MyThread implements Runnable {    public static void main(String[] args) {        MyThread my = new MyThread();                     //(1)        Thread a = new Thread(my);                        //(2)        a.start();                                        //(3)        System.out.println("This is main thread.");       //(4)    }    public void run(){        System.out.println("This is another thread.");    //(5)    }}

这里写图片描述
利用接口产生线程,其关系可以描述为:线程对象调用 Runnable 接口实现对象的 run 方法。程序执行过程中,在(4)和(5)处的代码可以看成是并发执行的。

0 0