多线程:Runnable接口实现多线程

MyRunnable.java

package test2;

public class MyRunnable  implements Runnable{
	String name;

	public MyRunnable(String name) {;
		this.name = name;
	}
	
	public void run(){
		System.out.println("执行了线程中的run()方法!方法名:"+this.name);
		try {
			Thread.sleep(5000); //休眠5秒
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

test.java

package test2;

public class test {

	public static void main(String[] args) {
		MyRunnable mr1=new MyRunnable("aaa");
		MyRunnable mr2=new MyRunnable("bbb");
		MyRunnable mr3=new MyRunnable("ccc");
		
		Thread t1=new Thread(mr1);
		Thread t2=new Thread(mr2);
		Thread t3=new Thread(mr3);
		
		t1.start();
		t2.start();
		t3.start();
	}
}

Runnable

阅读剩余
THE END