日期:2014-05-20 浏览次数:20765 次
class ThreadUse implements Runnable{ public String name=""; public ThreadUse(String str) { this.name=str; } public void run() { System.out.println("ThreadUse1 is running..."); for(int i=0;i<10;i++) { System.out.println(name+":"+i); } System.out.println(name+":I am the end!"); } } class ThreadUse2 extends Thread{ private String name = ""; public ThreadUse2(String str){ name= str; } public void run(){ System.out.println("ThreadUse2 is running..."); for(int i=0;i<10;i++) { System.out.println(name+":"+i); } System.out.println(name+":I am the end!"); } } public class Contest { public static void main(String args[]) { //Runnable接口类的对象创建线程 Thread number1 = new Thread(new ThreadUse("number1")); //Thread类的子类创建线程 ThreadUse2 number2 = new ThreadUse2("number2"); number1.setPriority(4); number2.setPriority(4); number1.start(); number2.start(); } }