1. 程式人生 > >Thread和Runnable的實現

Thread和Runnable的實現

1、Thread

package com.zzm.th01;

/**
 * 執行緒呼叫的隨機性
 * Created by ming on 2017/6/15.
 */
public class th02 extends Thread{
    @Override
    public void run() {
        super.run();
        System.out.println("mythread");
    }

    public static void main(String[] args) {
        th02 th = new th02();
        th.start();
        System.out.println("執行結束"
); } }

2、Runnable

package com.zzm.th01;

/**
 * Created by ming on 2017/6/15.
 */
public class th03 implements Runnable{
    @Override
    public void run() {
        System.out.println("執行");
    }

    public static void main(String[] args) {
        Runnable rb = new th03();
        Thread td = new
Thread(rb); td.start(); } }

3、兩者區別
(1)java不支援多繼承;
(2)java支援多實現;
注意:start()的呼叫順序不是執行緒的執行順序!!