admin管理员组

文章数量:1636966

package com.vince.thread;

import java.util.Date;

/**
 * Multi-Thread Implemention
 * 1. Extend class thread
 * 2. Implement interface Runnable
 * @author HarryKuma
 *
 */
public class ThreadDemo {

    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        myThread.start();
        for (int i = 0; i < 20; i++) {
            System.out.println("main-"+i);
        }

        MyRunnable myRunnable = new MyRunnable();
        Thread threadImpleRun = new Thread(myRunnable);
        threadImpleRun.start();
        
    }
}

class MyThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(new Date()+"-"+i);
        }
    }
}

class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("MyRunnale-"+i);
        }
    }    
}














本文标签: methodJavaDemothreadMulti