Java 继承Thread类实现多线程:

package test;

import java.io.*;
import java.lang.*;
import java.util.*;

class tThread extends Thread {
	public tThread(String st) {
		super(st);
	}
	public void run(){
		for (int i = 0; i < 10; ++i){
			System.out.println(i + " " + this.getName());
			try{
				this.sleep((int)Math.random()*10);
			}
			catch(Exception e){
				System.out.println(e.toString());
			}
			
		}
	}
}

public class gbx12{
	public static void main(String args[]) {
		tThread r1 = new tThread("ME");
		tThread r2 = new tThread("You");
		r1.start();
		r2.start();
	}
}

  

posted @ 2012-11-29 15:28  E_star  阅读(357)  评论(0编辑  收藏  举报